superphonic
superphonic

Reputation: 8074

.htaccess mod_rewrite based on domain

I have the following rule in my htaccess, I need to modify it to add variable to the end of the re-written url. Basically I have two domains pointing to the same hosting, and I am showing different sites depending on which domain it used.

RewriteCond %{HTTP_HOST} ^(www\.)?rrr\.me 
RewriteCond %{REQUEST_URI} !^/rrr
Rewriterule ^(.*)$ /rrr/$1 [L]

If someone goes to rrr.me or www.rrr.me they get the index.php in the rrr directory of my website. This works great!

I now need to be able to add a variable to the index.php. So someone will type in rrr.me/abc and it will append the abc to the end of the index.php in this fashion index.php?var1=abc

NEW REWRITE RULES AFTER ADVICE FROM Olaf Dietsche IN COMMENTS.

RewriteCond %{HTTP_HOST} ^(www\.)?rrr\.me 
RewriteCond %{REQUEST_URI} !^/rrr
RewriteCond %{REQUEST_URI} !/assets/
Rewriterule ^.*$ /rrr/index.php?rrr=$0 [L]

RewriteCond %{HTTP_HOST} ^(www\.)?rrr\.me
RewriteCond %{REQUEST_URI} !^/rrr
Rewriterule ^assets/.*$ /rrr/$0 [L]

Upvotes: 0

Views: 894

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74048

To append the requested URL as a query string

Rewriterule ^.*$ /rrr/index.php?var1=$0 [L]

To exclude the assets directory, you must use an additional RewriteCond

RewriteCond %{HTTP_HOST} ^(www\.)?rrr\.me
RewriteCond %{REQUEST_URI} !^/rrr
RewriteCond %{REQUEST_URI} !/assets/
Rewriterule ^(.*)$ /rrr/$1 [L]

For the assets files, you can use a similar redirect

RewriteCond %{HTTP_HOST} ^(www\.)?rrr\.me
RewriteCond %{REQUEST_URI} !^/rrr
Rewriterule ^assets/.*$ /rrr/$0 [L]

Upvotes: 1

Related Questions