how to redirect FIRST and then rewrite using mod_rewrite
I have two domains pointing to the same host, say example1.com and example2.com.
I already have a redirect:
RewriteRule ^([A-Za-z0-9-]+)/$ page.php?q=$1 [L]
to catch things like example1.com/hello-world/ => example.com/page.php?q=hello-world
Now I need 3 specific conditions to be met:
1) example1.com/special/ => example2.com/special/ [ONLY for "special"]
2) example2.com/ => example2.com/special/ 3) example2.com/anything-not-special/ => example1.com/anything-not-special/I can get this to hap开发者_开发百科pen, except that I want exactly what's in the right-hand column here to be displayed in the URL bar. Instead, I'm getting: example2.com/special/ => example1.com/page.php?q=special
which is not ideal for me.
Any help appreciated, thanks!
See if this does what you want:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/page\.php
RewriteCond %{HTTP_HOST}%{REQUEST_URI} =example1.com/special/ [OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} =example2.com/
RewriteRule ^.*$ http://example2.com/special/ [R=301,L]
RewriteCond %{REQUEST_URI} !^/page\.php
RewriteCond %{HTTP_HOST} =example2.com
RewriteCond %{REQUEST_URI} !=/special/
RewriteRule ^.*$ http://example1.com%{REQUEST_URI} [R=301,L]
RewriteRule ^([A-Za-z0-9-]+)/$ page.php?q=$1
精彩评论