如何使用 htaccess 将 www 网址重定向到非 www 网址?

发布于 2024-10-07 16:49:47 字数 221 浏览 0 评论 0原文

我想知道如何将用户从 http://www.mysite.com 重定向到 http://mysite.com 使用 htaccess,我不熟悉如何操作此文件来执行此操作,任何人都可以帮助我完成此操作?

提前致谢。

I wanted to know how to redirect users from http://www.mysite.com to http://mysite.com using htaccess, I'm not familiar in how to manipulate this file in order to do this, can anyone help me accomplish this?

Thanks in advance.

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

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

发布评论

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

评论(4

叹倦 2024-10-14 16:49:47

这个网站给出了完整的答案:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^domain\.com
RewriteRule (.*) http://domain.com/$1 [R=301, L]

它是当我用谷歌搜索它时出现的第一件事,所以我假设你甚至没有费心去寻找答案(顽皮的孩子,啧,啧!)。

This site gives a complete answer:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^domain\.com
RewriteRule (.*) http://domain.com/$1 [R=301, L]

It was the first thing that appeared when I googled for it, so I assume you didn't even bother to look for an answer (naughty boy, tsk, tsk!).

盛装女皇 2024-10-14 16:49:47

只需添加以下内容:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) http://mysite.com/$1 [R=301,L]

Just add this:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) http://mysite.com/$1 [R=301,L]
垂暮老矣 2024-10-14 16:49:47

像这样的东西应该可以解决

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^www\.(.*)$ $1 [NC]

你想要谷歌“htaccess rewrite”以找到更多信息的技巧

something like this should do the trick

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^www\.(.*)$ $1 [NC]

you want to google for "htaccess rewrite" to find more info about it

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