需要帮助将 http://website.com/ 重定向到 http://www.website.com/
我想做的是将输入 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个 mod_rewrite 示例:
这将附加
www.< /code> 到主机不以
www.
开头的每个请求,并使用永久重定向重定向到它。 URI 协议也被保留,但您可能需要添加一个条件以仅重定向特定的请求方法(例如 GET 和 HEAD)。Try this mod_rewrite example:
This will append
www.
to every request that’s host does not start withwww.
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).如果您使用 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.
您可能想检查这个与 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.