【问题标题】:Remove URL parameter from Wordpress URL从 Wordpress URL 中删除 URL 参数
【发布时间】:2015-08-13 17:04:36
【问题描述】:

我有一个使用“帖子名称”固定链接设置的 wordpress 网站。

我还在我的网站中设置了一个带有 URL 变量的链接:

http://www.xxxxxxxxxx.com/test/?location=London

我想将此 URL 修改为 http://www.xxxxxxxxxx.com/test/London

但是对于 wordpress 网站的其余部分来说,它把 htaccess 搞乱了

我已经尝试了以下 htaccess:

# 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]
//remove location name
RewriteRule ^([a-zA-Z0-9_-]+)$ /test/?location=$1
</IfModule>
# END WordPress

【问题讨论】:

    标签: wordpress .htaccess


    【解决方案1】:

    我知道有两种方法可以实现:

    RewriteCond %{QUERY_STRING}    "location=" [NC]
    RewriteRule (.*)  /test/$1? [R=301,L]
    

    要确保查询被删除,您需要将代码行移到 RewriteBase / 下方。所以它看起来像:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{QUERY_STRING}    "location=" [NC]
    RewriteRule (.*)  /test/$1? [R=301,L]
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    

    您还可以使用简化的重写规则删除查询

    RewriteCond %{QUERY_STRING} .
    RewriteRule ^$ /location? [R,L]
    

    【讨论】:

      猜你喜欢
      • 2017-12-25
      • 2016-09-02
      • 2014-10-25
      • 1970-01-01
      • 2012-05-19
      • 2016-05-17
      相关资源
      最近更新 更多