本文介绍了使用 .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
我想从 URL 末尾删除 ?post_type=question
.
I would like to remove ?post_type=question
from the end of URL.
我在 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 末尾删除查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!