htaccess WordPress中的重定向问题

问题描述:

我在htaccess中有以下重定向WordPress安装在主文件夹中该站点必须重定向example.com(不带www)并且使用https
WordPress安装在/ home中

I have the following redirects in htaccess Wordpress is installed in home folder The site must redirect an example.com (without www) and with https The wordpress installation is in / home

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

And I don't know how to fix it. Any suggestions? Thank you !!

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```


您不能强制子文件夹或子域重定向到https

You can't force subfolder or subdomain to redirect to https

要进行https重定向,请仅使用

for https redirection just use this

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

对于子文件夹

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

还可以使用默认的.htaccess进行重定向

also you can use the default .htaccess for redirection

<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>