【问题标题】:.htaccess and wordpress redirects problem.htaccess 和 wordpress 重定向问题
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 这非常适用于根文件夹中的网站,我通过将 wordpress 转移到根文件夹解决了这个问题,我放弃了将它放在子文件夹中的想法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多