Jump to content

Easier way of doing this?


ukweb

Recommended Posts

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]

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.