【发布时间】:2019-03-20 13:41:29
【问题描述】:
我的网站中有这样的结构:
/
/portal
当有人进入 www.example.com 时,它应该重定向到 https://www.example.com/portal,但不应显示门户,因此,地址栏应如下所示:https://www.example.com
由于这是一个 WordPress + Woocomerce 网站,我还需要一些重定向,例如:
http://www.example.com/carrito 到 https://www.example.com/carrito
问题是此时,当我输入http://www.example.com/carrito 时,它会将地址栏更改为https://www.example.com/portal/carrito
目前我有这个 .htaccess 文件:
/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?
example.com$
RewriteCond %{REQUEST_URI} !^/portal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /portal/$1
RewriteCond %{HTTP_HOST} ^(www.)?
example.com$
RewriteRule ^(/)?$ portal/index.php [L]
</IfModule>
/portal/.htaccess
RewriteEngine On
# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
# Redirect to https version
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L]
# RewriteCond %{SERVER_PORT} ^80$
# RewriteRule ^(.*)$ https://%{SERVER_NAME}/%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
【问题讨论】:
标签: wordpress apache .htaccess redirect mod-rewrite