Forum Moderators: phranque

Message Too Old, No Replies

Prevent a Root .htaccess from affecting subdomains in GoDaddy

.htaccess affecting subdomains in GoDaddy site

         

feralreason

5:37 am on Feb 27, 2012 (gmt 0)

10+ Year Member



I have a website on GoDaddy with several subdomains, each of which contains an in-progress website (for review by clients.)

In GoDaddy, subdomains are handled structurally as sub-directories so, when I added my typical .htaccess file to the root directory, all subdomains were disrupted (couldn't find css files, etc.)

Here is the type of .htaccess I would like to use in the root directory to handle mod rewrites for the main website:


RewriteEngine on
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ http://www.mymainsite.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.mymainsite\.com
RewriteRule (.*) http://www.mymainsite.com/$1 [R=301,L]


I'm not sure if there is any way to leave subdomains unaffected by this -- but I thought I would ask ...

Thx

phranque

4:27 am on Mar 1, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i would add RewriteCond(s) that test the path to the requested resource (directory location) or requested hostname where necessary to avoid executing RewriteRule(s)

lucy24

5:29 am on Mar 1, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

I'm not sure if there is any way to leave subdomains unaffected by this

When you set down a Rule + Condition that explicitly says to redirect everything to the main site, it's safe to say there is no way subdomains would not be affected.

Are there wild-card subdomains involved, or do you have a fixed number of named subdomains? This will make a pretty big difference in your overall complexity.

Basically you have a four-way split:

1. garbage.example.com >> nonexistent subdomains
Get rid of these requests right away, before they get mixed up with anything else.

2. subdomain.example.com >> all subdomains that actually exist
Intercept these at the beginning to exclude them from all further rewrites.

3. www.example.com >> your primary domain with name in its preferred form
Once you've got rid of the subdomains you handle the "meat" of your rewrites and redirects

4. example.com, www.example.com:80 etc >> requests for main domain in non-standard form
Wrap up with a final redirect to pick up any requests for your main site that aren't in the canonical form.

feralreason

7:23 am on Mar 1, 2012 (gmt 0)

10+ Year Member



phranque and lucy24 - thanks so much for your replies ! I've already taken care of this by placing .htaccess files in the directories for the subdomains with simply the command

RewriteEngine off

That seems to have solved the problem. Again, thanx for the responses.

g1smd

8:06 am on Mar 1, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Where you have used .* at the beginning of a pattern, change it to (([^/]+/)*)

Never use .* at the beginning or in the middle of a pattern.

Add a blank line after every RewriteRule to make the code more readable. Add a # comment to each block of code explaining what it does.