FreePgs.com Forum

FreePgs Related => Support Requests => Topic started by: brainiac744 on February 16, 2006, 01:52:54 AM

Title: htaccess subdomains
Post by: brainiac744 on February 16, 2006, 01:52:54 AM
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 :)
Title: Re: htaccess subdomains
Post by: webzone (archived) on February 16, 2006, 03:20:59 AM
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]
Title: Re: htaccess subdomains
Post by: brainiac744 on February 16, 2006, 03:41:08 AM
I changed the % to a $ and now I get a 500 internal server error.
Title: Re: htaccess subdomains
Post by: webzone (archived) on February 16, 2006, 05:31:56 AM
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.
Title: Re: htaccess subdomains
Post by: brainiac744 on February 16, 2006, 09:05:18 PM
Alright, thanks :)
Title: Re: htaccess subdomains
Post by: brainiac744 on February 17, 2006, 10:02:25 PM
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 :)
Title: Re: htaccess subdomains
Post by: webzone (archived) on February 18, 2006, 12:12:46 AM
Ironically, I've found the piece of code you're talking about only a few minutes before reading your post. :P
Title: Re: htaccess subdomains
Post by: brainiac744 on February 18, 2006, 01:51:57 AM
Hehe, well, thanks for finding it anyway :D