7

我正在尝试从 URL 末尾删除字符串:

例如我有这样的结构:

http://sitename.com/category/first-category-name/?post_type=question
http://sitename.com/category/second-category-name/?post_type=question
http://sitename.com/category/...-category-name/?post_type=question

我想?post_type=question从 URL 的末尾删除。

我在stackoverflow上找到了很多例子,但没有一个适合我。

谢谢你。

4

2 回答 2

20

这很简单,只需使用:

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

如果要将其添加到 wordpress 网站,则需要在任何 wordpress 规则之前添加它:

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

但是之后

RewriteBase /
于 2012-12-29T15:36:06.447 回答
4

只需执行以下操作:

RewriteEngine On
RewriteBase /
# Make sure there is a query string
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*  /? [R=301,L]

将 a?放在末尾以在存在时删除查询。

于 2012-12-28T20:57:29.920 回答