我正在尝试从 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 上找到了很多例子,但没有一个适合我。
谢谢你。
最佳答案
很简单,只需使用:
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 /
关于url - 使用 .htaccess 从 URL 末尾删除查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14071671/