wordpress - .htaccess 和 wordpress 重定向问题
问题描述
我的网站中有这样的结构:
/
/portal <--(WordPress 文件夹)
当有人进入 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
解决方案
尝试更新 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
推荐阅读
- node.js - 如何在猫鼬中从.exec返回项目,exec中的console.log返回元素但在外部返回未定义
- python - 如何合并多个工作表并用工作表名称重命名列名?
- c++ - 我的 buildHeap 函数中的逻辑错误是什么?
- sql - 有没有办法防止用户在 PosgreSQL 中进行洪水插入?有某种速率限制吗?
- reactjs - 如何使用下一个优化图像将外部图像导入静态文件夹?
- python-3.x - 第二个程序运行时 Python 脚本不启动
- pdf - 如何从 pdf 超链接以添加事件
- python - 错误:命令出错,退出状态为 1:尝试在窗口中“点安装量子格罗夫”时
- android - MoshiConverterFactory 不可访问
- java - 锯齿状数组的顺序填充。这段代码是如何工作的?