【问题标题】:How to do "Two 301 Redirects to One 301 Redirect" Wordpress如何做“两个 301 重定向到一个 301 重定向”Wordpress
【发布时间】:2019-06-06 14:35:17
【问题描述】:

我需要在 Wordpress 网站上进行一次 301 重定向而不是两次

我需要https://www.example.com/sports/test/index.php -> https://www.example.com/sports/test

我有两次 301 重定向 https://www.example.com/sports/test/index.php -> https://www.example.com/sports/test/ -> https://www.example.com/sports/test

我在 Wordpress 上有一个结构为 http://www.example.com 的网站,然后我购买了 ssl-sertificate 和我现在的结构 https://www.example.com
设置:
1) 固定链接 -> 自定义结构 https://www.example.com/%category%/%postname%/
2) 类别前缀 -> 。 (只是点)
3) .htacess(使用 Wordpress 的原始 URL 规则)

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#use many recomendation
#-------like this
#RewriteCond %{HTTP_HOST} ^example\.com [NC]
#RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
#-------end like this

#-------like this
#RewriteEngine on
#RewriteCond %{HTTP_HOST} !^www\. [OR]
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
#RewriteRule ^ https://www.%1%{REQUEST_URI} [NE,L,R=301] 
#-------end like this

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

# END WordPress

一切正常,但有两次 301 重定向或多次循环重定向,我需要在 WP 网站上重定向一次。谢谢你帮助我)

【问题讨论】:

    标签: wordpress .htaccess redirect url-rewriting url-redirection


    【解决方案1】:

    尝试更改永久链接结构并重新保存。

    如果 .htaccess 是 wordpress 默认的,你应该没有问题。

    对于 https 我使用这个插件https://it.wordpress.org/plugins/really-simple-ssl/ 非常简单易用且高效。

    告诉我

    【讨论】:

    • 1) 我在重新保存永久链接结构后默认重新保存了很多次
      .htacess,并且我已经安装了real-simple-ssl插件
      截图prntscr.com/nyh1g8
    【解决方案2】:

    RewriteEngine On 之后和 RewriteBase / 之前添加以下行:

    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{THE_REQUEST} " /(index\.php|([^?]*)/index\.php)"
    RewriteRule ^ https://www.example.com/%2 [R=301,L,NE]

    对我来说很好用

    【讨论】:

      猜你喜欢
      • 2012-04-20
      • 2017-10-06
      • 2013-02-28
      • 1970-01-01
      • 2021-06-22
      • 2015-08-03
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      相关资源
      最近更新 更多