ukweb Posted February 17, 2010 Share Posted February 17, 2010 Hi I've redesigned the site in work, and am having problems with our archives. Basically the redirect works nicely, but there are two problems with it; 1. The redirect appends the query string to the redirect, ie news_archive.php?month=1 redirects to /archives/1?1 instead of just /archives/1 2. I have a condition and a rule for every month, is there not a way of putting it into 1 line? Here's the code. Thanks in advance! RewriteCond %{QUERY_STRING} ^month=1$ RewriteRule ^news_archive.php$ http://www.uspcreative.com/archives/1 [R=301,L] RewriteCond %{QUERY_STRING} ^month=2$ RewriteRule ^news_archive.php$ http://www.uspcreative.com/archives/2 [R=301,L] RewriteCond %{QUERY_STRING} ^month=3$ RewriteRule ^news_archive.php$ http://www.uspcreative.com/archives/3 [R=301,L] RewriteCond %{QUERY_STRING} ^month=4$ RewriteRule ^news_archive.php$ http://www.uspcreative.com/archives/4 [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/192368-easier-way-of-doing-this/ Share on other sites More sharing options...
cags Posted February 17, 2010 Share Posted February 17, 2010 Everywhere I look seems to indicate that simply placing a question mark at the end of your target address will nullify the QUERY_STRING, having said that I've tested it and it doesn't seem to work on my system. I just thought I'd mention it just in-case you have more success with it. RewriteCond %{QUERY_STRING} ^month=1$ RewriteRule ^news_archive.php$ http://www.uspcreative.com/archives/1? [R=301,L] Alternatively how about the more succinct... RewriteCond %{QUERY_STRING} ^month=([0-9]{1,2})$ RewriteRule ^news_archive.php$ http://www.uspcreative.com/archives/%1? [R=301,L] This does work for me. It will obviously also redirect month=13 etc. but that will obviously just throw a 404 file not found error. If this is a problem for you there's probably a workaround. Quote Link to comment https://forums.phpfreaks.com/topic/192368-easier-way-of-doing-this/#findComment-1013701 Share on other sites More sharing options...
cags Posted February 17, 2010 Share Posted February 17, 2010 I think this should work... RewriteCond %{QUERY_STRING} ^month=([1-9]|1[0-2])$ RewriteRule ^news_archive.php$ http://sandbox/archives/%1? [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/192368-easier-way-of-doing-this/#findComment-1013705 Share on other sites More sharing options...
ukweb Posted February 17, 2010 Author Share Posted February 17, 2010 This worked a treat! Thanks for your help! I think this should work... RewriteCond %{QUERY_STRING} ^month=([1-9]|1[0-2])$ RewriteRule ^news_archive.php$ http://sandbox/archives/%1? [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/192368-easier-way-of-doing-this/#findComment-1013710 Share on other sites More sharing options...
cags Posted February 17, 2010 Share Posted February 17, 2010 Oops, just realised I left my test URL in, never mind eh? Glad it's working for you. Quote Link to comment https://forums.phpfreaks.com/topic/192368-easier-way-of-doing-this/#findComment-1013717 Share on other sites More sharing options...
ukweb Posted February 17, 2010 Author Share Posted February 17, 2010 Haha yes, I noticed tho! Ta very much! It's more for the search engines more than anything, no 404's now! Oops, just realised I left my test URL in, never mind eh? Glad it's working for you. Quote Link to comment https://forums.phpfreaks.com/topic/192368-easier-way-of-doing-this/#findComment-1013719 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.