我无法使用htaccess文件重定向。
我要重定向的内容
https://www.example.com
https://example.com
http://www.example.com
http://example.com
到
https://example.com/subdirectory and keep the url https://example.com
这是我到目前为止所拥有的:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www. example.com$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /subdirectory/$1 [L]
但它不会将https://www.example.com重定向到https://example.com
我想念什么?
答案 0 :(得分:0)
删除
RewriteCond %{HTTP_HOST} ^ example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www. example.com$
并替换为
#Redirect www and http
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]