Forum Moderators: phranque
This time I am in a fix to redirect some dynamic URLs to the root domain
For example:
example.com/?page_id=9
example.com/?page_id=20
example.com/?page_id=200
example.com/?cat=9
example.com/?cat=20
example.com/?cat=200
all these will redirect to the root domain example.com
Any help on this will be much appreciated...as always :)
RewriteCond to look at the QUERY_STRING. Do you want to redirect only those six listed URLs, all URLs with a cat or page_id parameter, or what?
The redirect is fairly simple. The examples in the library will serve to give you what you need.
Post your best effort code back here if you get stuck.
You'll need a RewriteCond to look at the QUERY_STRING.
I need to redirect all URLs with the cat or page_id parameter in it.
First step:
RewriteCond %{QUERY_STRING} &?(catŠid)=[0-9]+&?
Have a go. Chin up, bit of effort...
Jim
[edited by: jdMorgan at 10:19 pm (utc) on Jan. 31, 2009]
First step:RewriteCond %{QUERY_STRING} &?(catŠid)=[0-9]+&?
Now it's your turn... What rule do you think you should use?
Have a go. Chin up, bit of effort...
Wow..this is interesting.
Will it be
RewriteRule ^(catŠpage_id)=[0-9]+ http://www.example.com/ [R=301,L]
Also won't the Query String be
RewriteCond %{QUERY_STRING} &?(catŠpage_id)=[0-9]+&?
Also I would like to know what the & means in the RewriteCond
If the RewriteRule provided by me is wrong, tell me where I went wrong and I will give it another shot.
I really like this approach...this way you just don't spoonfeed but let the other users learn it themselves as well :-)
Thanks a lot Jd
RewriteRule cannot 'see' the query string, so put the name pf the page in the pattern, or (.*) for 'all' pages. Be as specific as possible, so the rule is checked only when needed, not for every request that hits your server (for images, css, js, etc). The
&? part of the pattern allows for the parameter to be the only parameter, the first or last of several parameters, or somewhere in the middle. Processing order: is the "left side" of the Rule, followed by the pattern in the Condition if the pattern in the rule was a match.