问题htaccess的WordPress的重定向(Problem with redirect in

2019-10-29 06:42发布

我在htaccess的WordPress的以下重定向安装在主文件夹中的网站必须重定向的example.com(加www),并以https WordPress的安装在/ home

我不知道如何解决它。 有什么建议么? 谢谢 !!

RewriteCond %{HTTP_HOST} ^example.com$
RewriteCond %{REQUEST_URI} !^/home/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /home/$1
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(/)?$ home/index.php [L]

# BEGIN SSL
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^example\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>

 # END SSL```

Answer 1:

你不能强迫子文件夹或子域名重定向到https

对于HTTPS重定向只是用这个

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

对于子文件夹

RewriteRule ^/?(.*) https://%{SERVER_NAME}/home/$1 [R,L]

你也可以使用重定向默认的.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


文章来源: Problem with redirect in htaccess wordpress