1

I have URLs with lots of parameters, here is an example that looks like this:

http://www.mysite.com/profile?reset=1&force=1&gid=9&custom_18=BS+Forestry%2C+University+of+Kentucky

I would like to do a RewriteRule that redirects any request containing the string:

&custom

To a static HTML page such as:

http://www.mysite.com/foo.html

Can someone tell me if/how this is possible?

Thanks a lot!

2
  • You should re-think your parameter scheme altogether, if you want decent page rank from search engines. Commented Sep 3, 2009 at 19:54
  • awesome idea, but it's not my software so i can't. i just need to do a redirect. Commented Sep 3, 2009 at 19:58

1 Answer 1

2

This should do the trick:

RewriteCond %{QUERY_STRING}  (^|&)custom(&|$)
RewriteRule ^(.*)$ http://www.mysite.com/foo.html [R]
Sign up to request clarification or add additional context in comments.

4 Comments

The (^|&) and (&|$) parts are to allow for cases like ?custom and &gid=1&custom--- while not matching ?**customfield**=irrelevant
gracias you are a kind person
QUESTION: this doesn't appear to work. I copied your info verbatim, changing only my domain. Nothing changed. I put the code near the top of the .htaccess file above all other ReWriteRules??
Add the L modifier, so the end looks like this: [R,L]. That'll fix the problem. (The L modifier will tell Apache to ignore the rules that you have below.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.