PDA

View Full Version : Mod rewrite on a subdomain with redirects


mrruben5
07-14-2005, 12:02 PM
I have a subdomain, and I want to send uri's to the new subdomain using a redirect:

http://www.mydomain.com/subdomain/^anythinghere$
must go to :

http://subdomain.mydomain.com/^anythinghere$

I also want mod rewrite:

http://subdomain.mydomain.com/^anythinghere$/

must be rewritten as:

http://subdomain.mydomain.com/index.php?q=^anythinghere$

How would I do this?

schleppel
07-14-2005, 06:09 PM
In you main domain root directory a .htaccess files with

RewriteEngine ON
RewriteRule ^/subdomain/?$ http://subdomain.mydomain.com/ [R,QSA]
RewriteRule ^/subdomain/(.*)/?$ http://subdomain.mydomain.com/$1 [R,QSA]

And in the subdomain root directory a .htaccess files with

RewriteEngine ON
RewriteRule ^(.*)$ index.php?q=$1 [QSA]


(i haven't actually tested this so if there's a problem just ask)
Ps. remember to change subdomain in the first .htaccess file to your subdomain's name.

mrruben5
07-15-2005, 12:55 AM
Thanks, that's exactly what I was looking for. :thumbsup: I understand that [R] will send a redirect header to the browser, but what does [QSA] do? Oh yeah, using the index.html to index.php?q=index with the R flag would break the use of mod_rewrite, hahaha.

This flag forces the rewriting engine to append a query string part in the substitution string to the existing one instead of replacing it. Use this when you want to add more data to the query string via a rewrite rule.

schleppel
07-15-2005, 04:48 PM
if you want http://subdomain.yourdomain.com/ to go to index.php?q=index you can use this:

RewriteEngine ON
RewriteRule ^$ index.php?q=index [QSA]
RewriteRule ^(.*)$ index.php?q=$1 [QSA]

mrruben5
08-08-2005, 10:22 AM
Another mod rewrite question. Can I "cloak" an url with mod_rewrite?

eg: http://www.encyshop to http://www.iceshop.nl/encyclue/store?