htaccess WordPress中的重定向问题 [英] Problem with redirect in htaccess wordpress

查看:81
本文介绍了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>

这篇关于htaccess WordPress中的重定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆