首页 文章

.htaccess域独立的www到非www与背驮式主页规则

提问于
浏览
1

https://stackoverflow.com/a/1270281/891052上有"Generic htaccess redirect www to non-www"的解决方案 . 它使网站301从www重定向到非www,而无需指定域名 .

它看起来像这样:

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

我试图完成的是添加一个规则,其中/ home重定向到根 .

换句话说,无论域名如何,http://example.com/homehttp://www.example.com/home都会转到http://example.com .

但我无法弄清楚如何 .

1 回答

  • 1

    您可以使用:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    
    RewriteRule ^home/?$ / [NC,L]
    

相关问题