Apache 重定向到子文件夹,但也将http重定向到https
我正在从URL直接重定向到子文件夹(例如:重定向Apache 重定向到子文件夹,但也将http重定向到https,apache,.htaccess,redirect,https,subdirectory,Apache,.htaccess,Redirect,Https,Subdirectory,我正在从URL直接重定向到子文件夹(例如:重定向www.example.com到www.example.com/subfolder),其工作原理如下: RewriteEngine on RewriteCond %{REQUEST_URI} !^/1 RewriteRule (.*) http://www.example.com/subfolder/$1 [L] RewriteEngine On RewriteCond %{SERVER_PORT} !^443$ RewriteRule
www.example.com
到www.example.com/subfolder
),其工作原理如下:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/1
RewriteRule (.*) http://www.example.com/subfolder/$1 [L]
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L]
此外(如果可能,使用相同的.htaccess文件),我想将任何http重定向到https,使用以下方法可以很好地工作:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/1
RewriteRule (.*) http://www.example.com/subfolder/$1 [L]
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [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]
谢谢!这是可行的,但需要进行以下修改:将第3行代码替换为:RewriteRule^https://%{HTTP\u HOST}%{REQUEST\u URI}[L,R]再次感谢您!