尝试301将所有网址重定向到特定子目录中的non-www
仅 。例如:
https://www.example.com/test
到
https://example.com/test
但是不重定向任何其他子目录,例如:
https://www.example.com/test1
应该保留www
更多示例:
https://www.example.com/test/country/city
到
https://example.com/test/country/city
答案 0 :(得分:0)
您可以使用它将www
的URL重定向到特定目录的non-www
:
RewriteEngine on
#the directory the rule should apply to
RewriteCond %{REQUEST_URI} ^/DirName/ [NC]
#check if the host string starts with "www"
RewriteCond %{HTTP_HOST} ^www\. [NC]
#redirect all www urls to non-www
RewriteRule (.*) http://example.com%{REQUEST_URI} [L,R=301]