【问题标题】:Wordpress htaccess rewrite rule not workingWordpress htaccess 重写规则不起作用
【发布时间】:2014-06-21 08:51:44
【问题描述】:

我想点击以下网址:

mysite.com/e-recording-counties/e-recording-in-utah

并让服务器接收:

mysite.com/e-recording-counties/state?state=utah

但看起来它正在变得:

mysite.com/e-recording-counties/state

浏览器位置显示:

mysite.com/e-recording-counties/state

这是我的 htaccess:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/e-recording-in-(.*)$ ?pagename=$1/state&state=$2 [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

任何帮助将不胜感激,我已经为此苦苦挣扎太久了。提前致谢!

【问题讨论】:

    标签: wordpress .htaccess mod-rewrite


    【解决方案1】:

    您需要使用 QSA 标志(查询字符串追加)

    https://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

    RewriteRule ^/e-recording-counties/e-recording-in-([a-z]+)$ /e-recording-counties/state?state=$1 [L,QSA,NC]
    

    编辑添加 - 上面的示例仅涵盖您作为示例提供的 URL。在查看了您自己的重写规则之后,我想我明白了您所追求的。

    RewriteRule ^/(.*)/e-recording-in-(.*)$ /index.php?pagename=$1/state&state=$2 [QSA,NC,L]
    

    【讨论】:

    • 戴夫,很遗憾,这不起作用。我在有和没有前导斜杠的情况下都试过了。它转到我想要的 URL (mysite.com/e-recording-counties/e-recording-in-utah),但服务器返回 404,表明它从未收到带有变量的 URL。
    猜你喜欢
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多