I am trying to redirect old URLS to the new URLS, the old site used variables in the URL but the new site uses SEO friendly URLs.

When I try to redirect the old URL, it is not redirecting correctly and I get 404 errors. I am unsure if the SEO rewrite is the cause of the other rewrite condition failing.

Options +FollowSymlinks RewriteEngine On

RewriteCond %{HTTP_HOST} ^example.com    
RewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteRule ^(.+).html index.php?seo_title=$1 [nc]    
Redirect 301 /WEBPAGE http://www.example.com/WEBPAGE.html    
RewriteRule ^http://www.example.co.uk/test/test.php?c=viewtest&id=56&sat=9&mainsat=1&start=0$ http://www.example.com/NEW_URL.html
ErrorDocument 404 /PAGE_NOT_FOUND.html

Question: How can I write the RewriteRule so that it redirects the old URL?


2 Answers 2


The problem I found was that the URL is split between the file and the variables as would be expected.

So everything after the ? is taken as a query string.

You need to add a condition to check the query string (you can include Regular Expressions)

RewriteCond %{QUERY_STRING} ^viewtest&id=56&sat=9&mainsat=1&start=0$  
RewriteRule ^/test/test.php$ http://www.example.com/WEBPAGE.html? [R=301,L]

Also, notice the ? after the redirected URL, this stops the variables being appended to the new URL


You can use javascript redirect on particular pages, If possible in your case.

  • 2
    That's not a good idea. If you want a redirect page instead of a transparent redirect, it's best to use the META REFRESH tag. That doesn't rely on JS (which web crawlers don't follow). But it's still best to use 301 if you want to transfer PageRank. Commented Oct 12, 2010 at 2:57
  • not possible the pages were dynamically generated from an older system that is no longer in use Commented Oct 13, 2010 at 14:44
  • @Craig: i hope you already had tried HTML redirect, JS redirect and .htaccess redirect. right? Commented Oct 14, 2010 at 2:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.