Dynamic url redirection, 500 error

Here’s what I have:

A site where all the URLs are in the form of http://mydomain.com/?i=100
The number at the end differs depending on the page

What I want to do:

Build a new site on mydomain.com and move the current site to http://sub.mydomain.com/?i=100

This new site will not have the same url structure, so the ?i=100 will not exist. Whenever that’s in the url, I want it to go to the subdomain.

What I tried:
My .htaccess only has this in it:

RewriteEngine On
RewriteRule ^?i=([0-9]+)$ http://sub.mydomain.com/?i=$1 [R=301,L]

I’m getting a 500 error though. I also tried a simple RedirectMatch and got the same results.

What am I missing?


What you’re missing is that the RewriteRule can ONLY examine the {REQUEST_URI} string for possible matches. When you need to look at the {QUERY_STRING}, you MUST use the RewriteCond statement.

Have a look at the code examples in my signature’s tutorial article.



This doesn’t work either:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://domain\\.com$ [NC]
RewriteCond %{HTTP_HOST} ^http://www\\.domain\\.com$ [NC]
RewriteRule ^?i=([0-9]+)$ http://sub.domain.com/?i=$1 [R=301,L]


Please READ my post above re {QUERY_STRING}.



Ah sorry about that

The following worked:

RewriteEngine On
RewriteCond %{QUERY_STRING} i=(.*)
RewriteRule ^(.*)$ http://sub.domain.com/?i=%1 [R=301,L]

Thanks so much! :slight_smile: