【问题标题】:.htaccess and 301 redirect (dynamic pages) wordpress.htaccess 和 301 重定向(动态页面)wordpress
【发布时间】:2012-10-09 11:09:57
【问题描述】:

我阅读了所有其他类似的问题,但不明白如何设置它,所以我的旧页面重定向到它们应该重定向的地方。

这是我的设置:

我的旧网站页面:

http://www.oldsite.com/blog/?p=1234
http://www.oldsite.com/blog/?p=432
http://www.oldsite.com/blog/?p=xxxx

我想像这样重定向前两个:

http://www.oldsite.com/blog/?p=1234 -> http://www.newsite.com/somewhere/on/mysite/
http://www.oldsite.com/blog/?p=432 -> http://www.newsite.com/somewhere/else/on/mysite/

并让所有其他页面(123、321、567、999...)重定向到我的主页,如下所示:
http://www.oldsite.com/blog/?p=***** -> http://www.newsite.com/

提前致谢!

【问题讨论】:

    标签: wordpress .htaccess redirect http-status-code-301 dynamic-pages


    【解决方案1】:

    您需要使用 mod_rewrite 的功能来匹配查询字符串,但所有规则都必须任何 wordpress 规则之前。

    RewriteEngine On
    
    # http://www.oldsite.com/blog/?p=1234 -> http://www.newsite.com/somewhere/on/mysite/
    RewriteCond %{QUERY_STRING} ^p=1234$
    RewriteRule ^/?blog/$ http://www.newsite.com/somewhere/on/mysite/ [L,R=301]
    
    # http://www.oldsite.com/blog/?p=432 -> http://www.newsite.com/somewhere/else/on/mysite/
    RewriteCond %{QUERY_STRING} ^p=432$
    RewriteRule ^/?blog/$ http://www.newsite.com/somewhere/else/on/mysite/ [L,R=301]
    
    # http://www.oldsite.com/blog/?p=***** -> http://www.newsite.com/
    RewriteCond %{QUERY_STRING} ^p=[0-9]+$
    RewriteRule ^/?blog/$ http://www.newsite.com/ [L,R=301]
    

    【讨论】:

    • 似乎我的 .htaccess 被兑现了,因为在我进行更改后它仍然像以前一样进入错误的页面......有没有办法强制刷新重定向?跨度>
    【解决方案2】:

    我尝试了@Jon Lin 代码,但它不适用于我的 WordPress 网站。我认为问题在于我正在运行 WordPress...我应该包含我的 .htaccess 代码,但我不认为 WP 会是问题...

    为了让它发挥作用,我必须做以下事情: 因为是 WP 站点,所以需要将代码放在 WP mod_rewrite 中。这是我重定向前的 .htaccess:

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

    之后:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_URI} ^/blog/$
    RewriteCond %{QUERY_STRING} ^p=998$
    RewriteRule . /some/where/over-there? [L,R=301]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    希望这将帮助其他运行 WP 并遇到同样问题的人!

    【讨论】:

      猜你喜欢
      • 2012-03-20
      • 1970-01-01
      • 2012-03-21
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      • 2017-10-06
      • 2013-02-28
      • 1970-01-01
      相关资源
      最近更新 更多