简体   繁体   English

从htaccess中删除括号(Helicon Ape)

[英]Remove parenthesis from htaccess (Helicon Ape)

I'm using Helicon Ape on a Windows Server to create htaccess files. 我在Windows Server上使用Helicon Ape创建htaccess文件。

Originally, part of a larger set of conditions, I had this condition set to return 403 if the url contained (). 最初,这是一组较大条件的一部分,如果url中包含(),则我将此条件设置为返回403。 However it is causing false positives in case of mailchimp tracking codes that end up getting wrapped in () 但是,如果mailchimp跟踪代码最终被包裹在()中,则会导致误报

 RewriteCond %{QUERY_STRING} ^.*(\\[|\\]|\\(|\\)|<|>).* [NC,OR] 

For example in the below URL 例如在下面的URL中

http://domain.com/page/11/page-name?ct=t(Newsletter_Tracking) http://domain.com/page/11/page-name?ct=t(Newsletter_Tracking)

As an alternative, I was attempting to remove the parenthesis and redirect to a "cleaned version". 作为替代方案,我试图删除括号并重定向到“清理后的版本”。

I tried a few different things that I found in SO but none worked. 我尝试了一些在SO中发现的不同方法,但没有任何效果。

So far the closest thing that I could get to working is this: 到目前为止,我可以开始工作的最接近的东西是:

 RewriteCond %{REQUEST_URI} [\\(\\)]+ [OR] RewriteCond %{QUERY_STRING} [\\(\\)]+ RewriteRule ^(.*)[\\(]+([^\\)]*)[\\)]+(.*)$ $1$2$3 [R=301,L] 

The problem with the above code is that works if the () were in the URL but not the query string. 上面的代码的问题是,如果()在URL中而不在查询字符串中,则该代码可以工作。 It doesn't redirect and clean the querystring. 它不会重定向和清理查询字符串。

So this would work: http://domain.com/page/11/pag(e-name) 这样就可以了: http : //domain.com/page/11/pag(e-name)

but this wouldn't: http://domain.com/page/11/page-name?ct=t(Newsletter_Tracking) 但这不会: http : //domain.com/page/11/page-name?ct=t(Newsletter_Tracking)

Your assistance is appreciated 感谢您的协助

Thank You. 谢谢。

You can use the following rule : 您可以使用以下规则:

RewriteCond %{THE_REQUEST} /page/11/page-name\?ct=t\(Newsletter_Tracking\)\sHTTP [NC]
RewriteRule ^  %{REQUEST_URI}? [L,R]

If the querystring is dynamic, try: 如果查询字符串是动态的,请尝试:

RewriteCond %{THE_REQUEST} /page/11/page-name\?ct=.+\(.+\)\sHTTP [NC]
RewriteRule ^  %{REQUEST_URI}? [L,R]

Using @starkeen 's example, I was able to create a working solution. 使用@starkeen的示例,我能够创建一个可行的解决方案。

This code handles the Query String separate from the URL. 此代码处理与URL分开的查询字符串。 It cleans the URL but removes the query string. 它清除URL,但删除查询字符串。

 RewriteCond %{REQUEST_URI} [\\(\\)]+ RewriteRule ^(.*)[\\(]+([^\\)]*)[\\)]+(.*)$ $1$2$3 [R=301,L] RewriteCond %{QUERY_STRING} [\\(\\)]+ RewriteRule ^ %{REQUEST_URI}? [R=301,L] 

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

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