News:

Click here for Toll-Free Service for your business starting at $2.00 per month

Main Menu

htaccess subdomains

Started by brainiac744, February 16, 2006, 01:52:54 AM

Previous topic - Next topic

brainiac744

Before anybody tells me to do it, I've already had the *.mydomain.com subdomain pointed to my root directory. Now, here's the problem:

I have this code:


RewriteCond %{HTTP_HOST} ^portal.mydomain.com(.*)$ [OR]
RewriteCond %{HTTP_HOST} ^www.portal.mydomain.com(.*)$
RewriteRule ^(.*)$ portal/%1 [L]


in my .htaccess file. It works, but it doesn't quite do what I want. Right now, any request, for any file by using portal.mydomain.com just redirects to the portal directory. For example portal.mydomain.com/somefile.php just goes to mydomain.com/portal. I want it to go to mydomain.com/portal/somefile.php. Any help is appreciated, thanks :)

webzone (archived)

You're using the wrong symbol. In RewriteRule, use $1 instead of %1.

RewriteCond %{HTTP_HOST} ^portal.mydomain.com(.*)$ [OR]
RewriteCond %{HTTP_HOST} ^www.portal.mydomain.com(.*)$
RewriteRule ^(.*)$ portal/$1 [L]

brainiac744

I changed the % to a $ and now I get a 500 internal server error.

webzone (archived)

QuoteI changed the % to a $ and now I get a 500 internal server error.

I think that's because, once your rewrite rules start working, they can create an infinite loop:
1. Request for /page on portal.domain.com
2. (Matches the RewriteRule so) Make new request for /portal/page on portal.domain.com
3. (Matches the RewriteRule again so) Make new request for /portal/portal/page on portal.domain.com
4. And so on...

I don't remember how I fixed that on my domain, but I'll try to take a look in the afternoon unless someone else answers before.

brainiac744


brainiac744

OK, good news, I found an old post by you and fixed it, I put this code into the /portal subdirectory for anybody interested:


RewriteEngine On
RewriteCond %{HTTP_HOST} !^portal.mydomain.com$
RewriteRule ^(portal/)?(.*)$ http://portal.mydomain.com/$2 [L,R=permanent]


Thanks for your help :)

webzone (archived)

Ironically, I've found the piece of code you're talking about only a few minutes before reading your post. :P

brainiac744

Hehe, well, thanks for finding it anyway :D