Hi,
What would my 301 redirect be if I wanted to redirect users from /page.php?page=about to /about/ ?
Thanks for any help
| SitePoint Sponsor |





Hi,
What would my 301 redirect be if I wanted to redirect users from /page.php?page=about to /about/ ?
Thanks for any help



Code:Redirect 301 /page.php?page=about /about/





Hi W1LL,
Unfortunately that doesn't seen to work for me
Can I PM you the link?



Yes of course you can, I'll take a look for you.



Just thought, you might need to include the whole address to forward to:
Code:Redirect 301 /page.php?page=about http://www.example.com/about/

iv2,
I don't think that mod_alias can look at the query string (certainly it can't use a match ... without using RewriteMatch) so I'd rely on mod_rewrite with:Regards,Code:RewriteEngine on RewriteCond %{QUERY_STRING} ^page=about$ RewriteRule page\.php$ about/ [R=301,L]
DK
David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
Updated mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator





Thanks for the replies.
DK,
I'm using this...
but when it repoints, it gives me http://www.test.com/about/?page=about sadlyCode:RewriteCond %{QUERY_STRING} ^page=about$ RewriteRule page\.php$ http://www.test.com/about/ [R=301,L]
Do you know why this is the case?
Thanks again





Side question:
Can RewriteCond be used with Redirect (or RedirectMatch)? Or only with RewriteRule and R flag?





Hey stomme,
This is in my 'htaccess' file.
It works, but then appends ?page=about to the redirected address.





You don't have any other rules (rewrite, etc) anywhere else?
I thought you needed the QSA flag to append query strings!





Aha:
http://www.simonecarletti.com/blog/2...-query-string/
Bleh, so if this guy is right it should beHowever, if you don’t append something new, then the original query is passed through the rules unchanged by default.
If you want to discard the original query string you must append an empty question mark at the end of the rule. Let’s call it the query string not append or query string discard flag.
But, I'm not sure.Code:RewriteCond %{QUERY_STRING} ^page=about$ RewriteRule page\.php$ about/? [R=301,L]





Wow, that ? did the job!!! Brilliant, stomme many thanks for your efforts.





Shoot, means I gotta change mine now too : )

poes,
Aw, you didn't find that ? (kill the query string) answer in my signature's tutorial? Hmmm, there must be TOO MUCH information there! Oh, well, it was the CORRECT answer!
RewriteCond is a part of Apache's mod_rewrite while Redirect (et al) are part of Apache's (core) mod_alias. In other words, RewriteCond cannot be used with Redirect or RedirectMatch. In fact, any and all mod_alias directives are acted upon BEFORE any mod_rewrite directives (priority).
Regards,
DK
David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
Updated mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator





Eeeek, sorry dklynn.
Will pay closer attention next time
Just glad I got it resolved![]()





I stupidly sought only what I knew had something to do with it... and remained sitting at the [QSA] flag section of the tut. I did the same thing at apache.org : ( looked at the flags.Aw, you didn't find that ? (kill the query string) answer in my signature's tutorial? Hmmm, there must be TOO MUCH information there! Oh, well, it was the CORRECT answer!
Bookmarks