如何在不破坏Wordpress的情况下删除.htaccess中的URL参数
我正在尝试从 WordPress 友好的 URL 中删除无关的参数,例如:
/foo-post-name.html?sf123456=1
我已将以下指令添加到 .htaccess
RewriteRule ^(?!wp-admin))(.*)$ $1? [R=301,L]
并且确保除 /wp-admin 之外的任何 URL 都会删除 URL 参数。然而,我刚刚意识到我还需要从 URL 参数 strippage 中排除像 /?p=12345&preview=true 这样的 URL。
我尝试将其更改为:
RewriteRule ^(?!wp-admin|p=))(.*)$ $1? [R=301,L]
...但这不起作用(500 服务器错误)。我应该如何修改我的正则表达式,以便 /?p=1234 不被重定向?
我需要支持的唯一参数是“p 和预览”。
I am trying to strip extraneous parameters off a Wordpress friendly URL, such as:
/foo-post-name.html?sf123456=1
I have added the following directive to .htaccess
RewriteRule ^(?!wp-admin))(.*)$ $1? [R=301,L]
And that ensures that any URL except /wp-admin will strip off the URL parms. However, I just realized I also need to exclude URLs like /?p=12345&preview=true from URL parameter strippage.
I've tried changing it to:
RewriteRule ^(?!wp-admin|p=))(.*)$ $1? [R=301,L]
...but that does not work (500 server error). How should I modify my regex so that /?p=1234 isn't redirected?
The only parameters I need to support is 'p and preview'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在 RewriteRule 中匹配查询字符串,但可以在 RewriteCond 中使用 *%{QUERY_STRING}* 进行匹配。这有点混乱,但这就是你想要做的吗?
You can't match against query strings in the RewriteRule, but you can in a RewriteCond using *%{QUERY_STRING}*. This is kind of messy but is this what you're trying to do?