简体   繁体   English

htaccess删除查询字符串

[英]htaccess remove query string

I'm not too familiar with regular expressions and I'm having trouble achieving what I want. 我对正则表达式不太熟悉,在实现所需内容方面遇到困难。

The website I'm working on used to have a wordpress blog on it and there are existing links on the internet pointing to http://www.website.com/?p=(random number). 我正在工作的网站上曾经有一个wordpress博客,并且互联网上有指向http://www.website.com/?p=(随机数)的现有链接。

The current code I have right now doesn't seem to work: 我现在拥有的当前代码似乎不起作用:

RewriteCond %{QUERY_STRING} p=(.*)
RewriteRule http://www.website.com/ [R=301,L]

In fact if there is a way to remove any kind of query string for the index page, that would be even better. 实际上,如果有一种方法可以删除索引页的任何类型的查询字符串,那会更好。

Thanks in advance. 提前致谢。

If you want to remove all query strings regardless 如果要删除所有查询字符串,无论

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

This tests if there is any query string . 这将测试是否有任何查询字符串. and then redirects to the home page without query string /? 然后重定向到没有查询字符串/?的主页/? .

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details. 切勿在启用301测试,请参阅此答案有关调试.htaccess重写规则的提示,以获取详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM