-1
有人可以請.htaccess文件中的適當指令讓我將www.host.com請求重定向到host.com,反之亦然?從www.host.com重定向到host.com的.htaccess
有人可以請.htaccess文件中的適當指令讓我將www.host.com請求重定向到host.com,反之亦然?從www.host.com重定向到host.com的.htaccess
這將重定向從http://www.yoursite.com到http://yoursite.com:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^yoursite\.com
RewriteRule (.*) http://yoursite.com/$1 [R=301, L]
這是相反的:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
以上就是我在我的服務器上使用,它完美的作品。
我不確定這些是否可行。我希望任何其他子域名都能正常工作,例如test.yoursite.com應該保持不變,只有www.yoursite.com需要刪除 – BusterX 2011-05-06 20:42:27
@BusterX歡迎並請在開始新問題前使用搜索:) http://stackoverflow.com/questions/4430617/how-to-redirect-www-url-to-non-www-url-with -htaccess – Prix 2011-05-06 06:19:07
和http://stackoverflow.com/questions/1659949/how-to-change-htaccess-to-redirect-all-non-www-links-to-www-pages – Prix 2011-05-06 06:27:30
屬於ServerFault。 – 2011-05-06 06:40:31