问题描述
我有一个使用帖子名称永久链接设置的wordpress网站。
I have a wordpress site that is using the "post name" permalink settings.
我还在我的网站中设置了一个URL变量链接:
I have also setup a link in my site with a URL variable:
我想将此URL修改为
I would like to modify this URL to just http://www.xxxxxxxxxx.com/test/London
但是它使htaccess混乱了WordPress网站的其余部分
but it's messing the htaccess up for the rest of the wordpress site
我尝试了以下htaccess:
I have tried the following 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
推荐答案
有两种方法我知道您可以实现:
There are two ways that I know you can achieve it:
RewriteCond %{QUERY_STRING} "location=" [NC]
RewriteRule (.*) /test/$1? [R=301,L]
要确保查询被删除,您需要移动代码行下面是RewriteBase /。因此看起来像这样:
to make sure the query gets deleted you need to move the code lines bellow RewriteBase / . so it looks like:
# 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
您还可以使用简化的重写规则删除查询
You can also remove the query using a simplified rewrite rule
RewriteCond %{QUERY_STRING} .
RewriteRule ^$ /location? [R,L]
这篇关于从Wordpress URL中删除URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!