使用.htaccess从URL末尾删除查询字符串 [英] remove query string from end of URL using .htaccess

查看:69
本文介绍了使用.htaccess从URL末尾删除查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to remove string from the end of URL:

例如,我具有这样的结构:

For example i have a structure like this:

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.

我发现了很多关于stackoverflow的例子,但是没有人适合我.

I found a lot of examples on stackoverflow, but no one works for me.

谢谢.

推荐答案

很简单,只需使用:

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

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

If you are going add this to wordpress website, you need add it before any wordpress rules:

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

但在

RewriteBase /

这篇关于使用.htaccess从URL末尾删除查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆