.htaccess mod_rewrite 重定向
示例#1(按预期工作):
RewriteCond %{HTTP_HOST} ^www.hanoichurch.com$ [OR]
RewriteCond %{HTTP_HOST} ^hicvn.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.hicvn.com$ [OR]
RewriteCond %{HTTP_HOST} ^hicvn.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.hicvn.org$ [OR]
RewriteCond %{HTTP_HOST} ^hanoiworship.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.hanoiworship.com$
RewriteCond %{REQUEST_FILENAME} !^google
RewriteRule ^/?(.*)$ "http\:\/\/hanoichurch\.com\/$1" [R=301,L]
示例#2(不起作用*):
RewriteCond %{HTTP_HOST} ^www.nathanbrauer.com$ [OR]
RewriteCond %{HTTP_HOST} ^nathanbrauer.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.nathanjbrauer.com$
RewriteCond %{REQUEST_FILENAME} !^google
RewriteRule ^/?(.*)$ "http\:\/\/nathanjbrauer\.com\/$1" [R=301,L]
*静默失败(访问 www.nathanbrauer.com 只是加载页面,不会重定向到 nathanjbrauer.com)。
一百万谢谢!
===更新===
我最终做的是使用这段代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^nathanjbrauer\.com$
RewriteCond %{REQUEST_FILENAME} !^google
RewriteRule ^ http://nathanjbrauer.com%{REQUEST_URI} [R=301,L]
Sample #1 (works as expected):
RewriteCond %{HTTP_HOST} ^www.hanoichurch.com$ [OR]
RewriteCond %{HTTP_HOST} ^hicvn.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.hicvn.com$ [OR]
RewriteCond %{HTTP_HOST} ^hicvn.org$ [OR]
RewriteCond %{HTTP_HOST} ^www.hicvn.org$ [OR]
RewriteCond %{HTTP_HOST} ^hanoiworship.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.hanoiworship.com$
RewriteCond %{REQUEST_FILENAME} !^google
RewriteRule ^/?(.*)$ "http\:\/\/hanoichurch\.com\/$1" [R=301,L]
Sample #2 (does not work*):
RewriteCond %{HTTP_HOST} ^www.nathanbrauer.com$ [OR]
RewriteCond %{HTTP_HOST} ^nathanbrauer.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.nathanjbrauer.com$
RewriteCond %{REQUEST_FILENAME} !^google
RewriteRule ^/?(.*)$ "http\:\/\/nathanjbrauer\.com\/$1" [R=301,L]
*Fails silently (visiting www.nathanbrauer.com simply loads the page and doesn't redirect to nathanjbrauer.com).
A million thanks!
=== Update ===
What I ended up doing was using this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^nathanjbrauer\.com$
RewriteCond %{REQUEST_FILENAME} !^google
RewriteRule ^ http://nathanjbrauer.com%{REQUEST_URI} [R=301,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的示例 1 代码也可以重构,但我只会建议修复您的示例 2 代码,因为这不适合您:
Your sample1 code can also be refactored but I will only suggest fixes to your sample 2 code since this is not working for you: