需要帮助将 http://website.com/ 重定向到 http://www.website.com/

发布于 2024-08-25 00:23:57 字数 258 浏览 2 评论 0原文

我想做的是将输入 example.com 的网站访问者重定向到 www.example.com

我会使用标准重定向来完成此操作,但我不知道如何创建特定于 WWW 或非 WWW 地址的站点。

我发现 Firefox 认为我的网站在 WWW 版本中明显不同,因为它在不使用缓存的情况下重新加载它。如何制作非 WWW 特定的 index.html 页面以将它们重定向到 www.example.com

What I'm trying to do is to redirect my website visitors who enter example.com to www.example.com.

I would do this with a standard redirect, but I don't know how to make a site specific to WWW or non-WWW addresses.

I see that Firefox thinks my site is clearly different at the WWW version, because it reloads it without using the cache. How can I make a non-WWW specific index.html page to redirect them to www.example.com?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

护你周全 2024-09-01 00:23:57

试试这个 mod_rewrite 示例:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

这将附加 www.< /code> 到主机不以 www. 开头的每个请求,并使用永久重定向重定向到它。 URI 协议也被保留,但您可能需要添加一个条件以仅重定向特定的请求方法(例如 GET 和 HEAD)。

Try this mod_rewrite example:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This will append www. to every request that’s host does not start with www. and redirect to it with a permanent redirect. The URI protocol is also preserved but you might want to add a condition to only redirect specific request methods (like GET and HEAD).

A君 2024-09-01 00:23:57

如果您使用 IIS,只需创建一个新网站,添加“mydomain.com”标头并使用 IIS 重定向功能重定向到 www.mydomain.com。

If you are using IIS simply create a new web site, add "mydomain.com" header and use IIS redirect feature to redirect to www.mydomain.com.

半岛未凉 2024-09-01 00:23:57

您可能想检查这个与 IIS 进行讨论的链接,这就是 stackoverflow.com 正在做的事情......您很可能会逆转事情的工作方式。

在 Jeff 的示例中,他从网址 http://www.stackoverflow.com/ 中删除了 {www.},但对于您来说,听起来你可以用他的例子,做相反的事情。

Jeff Atwood 的 StackOverflow 示例。

You may want to check this link that discusses it with IIS, and is the way that stackoverflow.com is doing it... you would most likely reverse the way things are working.

In Jeff's example, he is removing the {www.} from the url http://www.stackoverflow.com/, but for you, it sounds like you could use his example and do the opposite.

Jeff Atwood's Example for how they did it for StackOverflow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文