1

My application dynamically creates sub domains.

If just the subdomain is used (no other path): mydomain.mysite.com

I need the subdomain to remap/rewrite (keep the same URL so its hidden from the user) to the following url mydomain.mysite.com/event/mydomain

In the instance where there are other parameters passed then I want to ignore the rewrite rule. (mydomain.mysite.com/something/else)

I'm having trouble with the following endind up in a redirect loop

RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.mysite\.com
RewriteRule ^(.*)$ http:// %1.mysite.com/events/%1 [L,NC,QSA]

Its also rewriting when I pass other params!

mnel
  • 113,303
  • 27
  • 265
  • 254

1 Answers1

0

If you have http:// as part of your rule's target, then it will automatically redirect. You want it to internally rewrite so remove the http:// and hostname. You also want to match against the URI / because anything rlese you want to ignore the rule:

RewriteEngine on
# you may want this condition, to ignore "www"
RewriteCond %{HTTP_HOST} !^www\.

RewriteCond %{HTTP_HOST} ^(.*)\.mysite\.com
RewriteRule ^/?$ /events/%1 [L]

The first condition was added to ignore hosts that start with www, so that http://www.mysite.com/ won't get rewritten. If you don't care about that then just remove the condition. You also don't need the QSA flag because that's implicit when you don't have a ? in your target.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • THanks for the reply. I tried using those rules but when i ran subdomain.mysite.com it gives a 404 however subdomain.mysite.com/events/subdomain seems to run ok ? any ideas ? Cheers – user1861648 Dec 12 '12 at 10:30