Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to redirect accesses from

http://www.domain.com/test.php?sub=subdomain&type=cars

to

http://subdomain.domain.com/cars

I already have mod_rewrite rules to do the opposite:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
RewriteRule (.*) http://www.%2.com/index.php?route=$1&name=%1 [R=301,L]

What changes do I need to make to these rules to redirect requests from the script to the subdomain?

share|improve this question
    
Have you considered simply making this change in the PHP script? –  Charles Nov 16 '12 at 21:24

1 Answer 1

RewriteEngine On

RewriteCond %{QUERY_STRING} ^sub=(.+)&type=(.*)$
RewriteRule . http://%1.domain.com/%2?
share|improve this answer
    
thanks for respons but i am a another problem :: Cette page Web présente une boucle de redirection. input : [domain.com/test.php?sub=asdasd&type=456] output: (asdasd.domain.com/456?sub=asdasd&type=456) –  user1830181 Nov 17 '12 at 0:13
    
@KIRA remove the QSA argument in your RewriteRule –  Kamil Šrot Nov 17 '12 at 8:58
    
@KIRA ...or add question mark ? after the %2 w/o any white space - like this ...domain.com/%2? –  Kamil Šrot Nov 19 '12 at 10:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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