0

I'm using Helicon Ape on a Windows Server to create htaccess files.

Originally, part of a larger set of conditions, I had this condition set to return 403 if the url contained (). However it is causing false positives in case of mailchimp tracking codes that end up getting wrapped in ()

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

For example in the below URL

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 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. It doesn't redirect and clean the querystring.

So this would work: http://domain.com/page/11/pag(e-name)

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

Your assistance is appreciated

Thank You.

imvain2
  • 15,480
  • 1
  • 16
  • 21

2 Answers2

1

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]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • Thank you. However that is too specific which will cause issues. I came up with a working solution after seeing your use of REQUEST_URI in the RULE – imvain2 Nov 02 '16 at 15:51
1

Using @starkeen 's example, I was able to create a working solution.

This code handles the Query String separate from the URL. It cleans the URL but removes the query string.

RewriteCond %{REQUEST_URI} [\(\)]+

RewriteRule ^(.*)[\(]+([^\)]*)[\)]+(.*)$ $1$2$3 [R=301,L]

RewriteCond %{QUERY_STRING} [\(\)]+

RewriteRule ^ %{REQUEST_URI}? [R=301,L]
imvain2
  • 15,480
  • 1
  • 16
  • 21