Apache .htaccess重定向到子文件夹\u和\uhttps

Apache .htaccess重定向到子文件夹\u和\uhttps,apache,.htaccess,redirect,mod-rewrite,Apache,.htaccess,Redirect,Mod Rewrite,我在/public\u html/subfolder/中有一个域,因此我在public\u html中使用.htaccess来显示以下内容: RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ RewriteCond %{REQUEST_URI} !^/subfolder/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d

我在/public\u html/subfolder/中有一个域,因此我在public\u html中使用.htaccess来显示以下内容:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ 
RewriteCond %{REQUEST_URI} !^/subfolder/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /subfolder/$1 
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ 
RewriteRule ^(/)?$ subfolder/index.php [L]
它工作正常,但我想向https添加额外的重定向://

尝试了一些.htaccess修改,但没有成功:我收到重定向循环错误(“太多重定向”)或带有附加部分的URL,如:

子文件夹/page.html

反而


您可以使用以下规则将http重定向到https,并将根URI重定向到子文件夹

RewriteEngine on

#http to https
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
#rewrite root requests to subfolder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /subfolder%{REQUEST_URI} [L]

www.example.com替换为您的域名。

您可以使用以下规则将http重定向到https,并将根URI重定向到子文件夹

RewriteEngine on

#http to https
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
#rewrite root requests to subfolder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /subfolder%{REQUEST_URI} [L]

www.example.com替换为您的域名。

我有类似的配置,但在.htaccess中使用了两个条目。您可以在上查看我的配置

web内容位于子文件夹中,我正在使用.htaccess强制https://

我的.htaccess如下所示:

RewriteEngine On

#redirecting non-ssl to ssl:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R,L] 

#redirecting primary domain to subdirectory
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^subfolder/ [NC]
RewriteRule ^(.*)$ /subfolder/$1 [L] 
RewriteRule ^/?$ "https\:\/\/www\.example\.com\/" [R=301,L]

您可以对此进行测试,看看它是否适合您。如果有任何可以改进的地方,请放心。

我有一个类似的配置,但我在.htaccess中使用了两个条目。您可以在上查看我的配置

web内容位于子文件夹中,我正在使用.htaccess强制https://

我的.htaccess如下所示:

RewriteEngine On

#redirecting non-ssl to ssl:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://example.com/$1 [R,L] 

#redirecting primary domain to subdirectory
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^subfolder/ [NC]
RewriteRule ^(.*)$ /subfolder/$1 [L] 
RewriteRule ^/?$ "https\:\/\/www\.example\.com\/" [R=301,L]

您可以对此进行测试,看看它是否适合您。如果有任何改进,请放心。

是的,我以前检查过此解决方案:首先重定向到https://然后再重定向到子文件夹,但它会导致“重定向太多”错误是的,我以前检查过此解决方案:首先重定向到https://然后再重定向到子文件夹,但它会导致“重定向太多”错误