【问题标题】:.htaccess Use RewriteRule, but skip Wordpress rewrite on match.htaccess 使用 RewriteRule,但在匹配时跳过 Wordpress 重写
【发布时间】:2012-08-29 19:03:06
【问题描述】:

我最近asked a question about getting a specific Rewrite to work。我确实得到了一个可行的答案,并在我的一个网站上使用了它。现在我正在尝试重用这种方法,但我发现逻辑正在落入 Wordpress 重写部分,而我自己的重定向根本没有被触发。

# BEGIN Redirect deprecated site links to wp equivalent
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^news=13$
RewriteRule ^news_comments.php$ http://example.com/example-directory/ [R=301]
RewriteCond %{QUERY_STRING} ^news=51$
RewriteRule ^news_comments.php$ http://example.com/example-page.php [R=301]
</IfModule>
# END Redirect deprecated site links to wp equivalent

# 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,但我需要触发我在顶部指定的那些并跳过 Wordpress 规则。

我四处搜索并看到了一些使用类似...的建议

...
RewriteCond %{QUERY_STRING} ^news=51$
RewriteRule ^news_comments.php$ http://example.com/example-page.php [R=301]
RewriteRule ^news_comments.php$ - [L]
</IfModule>

...但我似乎无法让它工作。有什么想法吗?

【问题讨论】:

    标签: wordpress .htaccess mod-rewrite


    【解决方案1】:

    您需要确保将 [L] 标志添加到重定向的末尾,否则 URI 将继续通过其余规则并在末尾发生重定向。到那时,wordpress 已经使用 URI。

    RewriteCond %{QUERY_STRING} ^news=13$
    RewriteRule ^news_comments.php$ http://example.com/example-directory/ [R=301,L]
    RewriteCond %{QUERY_STRING} ^news=51$
    RewriteRule ^news_comments.php$ http://example.com/example-page.php [R=301,L]
    

    【讨论】:

    • 谢谢乔恩!你在这方面太棒了!
    猜你喜欢
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    相关资源
    最近更新 更多