CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Apache configuration (http://www.codingforums.com/forumdisplay.php?f=69)
-   -   Mod rewrite on a subdomain with redirects (http://www.codingforums.com/showthread.php?t=63480)

mrruben5 07-14-2005 11:02 AM

Mod rewrite on a subdomain with redirects
 
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 05:09 PM

In you main domain root directory a .htaccess files with
Code:

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
Code:

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-14-2005 11:55 PM

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.

[edit:NVM.]
Quote:

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.
[/edit]

schleppel 07-15-2005 03:48 PM

if you want http://subdomain.yourdomain.com/ to go to index.php?q=index you can use this:
Code:

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


mrruben5 08-08-2005 09: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?


All times are GMT +1. The time now is 09:46 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.