重定向到子文件夹,同时也将 http 重定向到 https
Redirecting to subfolder, but also redirect http to https
我正在从 URL 直接重定向到一个子文件夹(例如:将 www.example.com
重定向到 www.example.com/subfolder
),它工作得很好,如下所示:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/1
RewriteRule (.*) http://www.example.com/subfolder/ [L]
此外(如果可能的话,使用相同的 .htaccess 文件)我想将任何 http 重定向到 https,使用以下方法可以正常工作:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/ [L]
如何将这两个重定向合并到一个 .htaccess 文件中?所以最后从 http 重定向到 https 和 重定向到子文件夹?
非常感谢!
您可以使用以下规则
RewriteEngine on
#http to https
RewriteCond %{HTTPS} off
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R]
#Rewrite everything to subfolder
RewriteRule !subfolder /subfolder%{REQUEST_URI} [L]
我正在从 URL 直接重定向到一个子文件夹(例如:将 www.example.com
重定向到 www.example.com/subfolder
),它工作得很好,如下所示:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/1
RewriteRule (.*) http://www.example.com/subfolder/ [L]
此外(如果可能的话,使用相同的 .htaccess 文件)我想将任何 http 重定向到 https,使用以下方法可以正常工作:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/ [L]
如何将这两个重定向合并到一个 .htaccess 文件中?所以最后从 http 重定向到 https 和 重定向到子文件夹?
非常感谢!
您可以使用以下规则
RewriteEngine on
#http to https
RewriteCond %{HTTPS} off
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R]
#Rewrite everything to subfolder
RewriteRule !subfolder /subfolder%{REQUEST_URI} [L]