首页 > 解决方案 > .htaccess 和 wordpress 重定向问题

问题描述

我的网站中有这样的结构:

/

/portal <--(WordPress 文件夹)

当有人进入 www.example.com 时,它应该重定向到https://www.example.com/portal但不应该显示门户,因此地址栏应该如下所示:https://www.example.com

由于这是一个 WordPress + Woocomerce 网站,我还需要一些重定向,例如:

http://www.example.com/carritohttps://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

标签: wordpressapache.htaccessredirectmod-rewrite

解决方案


尝试更新 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 /

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


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

# END WordPress

按照链接获取更多详细信息 - https://in.godaddy.com/help/redirect-http-to-https-for-wordpress-on-linux-27904


推荐阅读