Go Back   HostGator Peer Support Forums > HostGator Peer Support Forums > Shared Hosting Support

Notices

Reply
 
Thread Tools
  #1  
Old 05-23-2008, 11:08 AM
paradigm's Avatar
paradigm paradigm is offline
Hatchling Croc
 
Join Date: May 2008
Posts: 5
Exclamation Fascinating problem with .htaccess and addon domain

I am moving a web site from another server to an addon domain on my HG account. I have successfully created an addon domain and have changed the DNS settings for the second web site. However, .htaccess file in the root directory is affecting the web site in the addon directory. I have special rewrite rules in the root .htaccess file for that website. I know that .htaccess files are global and affect subdirectories, but in this case I do not want the root .htaccess file to affect the addon directory. What happens right now is that www.eagledatainc.com (the addon directory, in public_html/eagledatainc) gets forwarded to www.turkishenglish.com (the root directory).

I tried the following directive, but it did not work:

ReWriteRule ^eagledatainc/.*$ - [L,R=301]

I am trying to write a rule at the top that will catch hits to the subdirectory and stop the substitution.

Here is the relevant part of the .htaccess file in the root directory:

DirectoryIndex root.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|tr)/?$ root.php?language=$1 [QSA,L]
RewriteRule ^(en|tr)/([-A-Za-z0-9_.]+)\.html$ root.php?language=$1&section=$2 [QSA,L]
RewriteRule ^(en|tr)/member\.php$ member.php?language=$1 [QSA,L]
RewriteRule ^administrator/?$ admin.php [QSA,L]
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ hack.php [L]
#ErrorDocument 404 /test/404.php

Any help would be greatly appreciated.
Reply With Quote
  #2  
Old 05-23-2008, 04:51 PM
slapshotw's Avatar
slapshotw slapshotw is offline
Veteran Croc
 
Join Date: Jun 2006
Posts: 5,164
Default Re: Fascinating problem with .htaccess and addon domain

If you don't need any rewriting in the subdirectory, what about putting this line in your subdirectory's .htaccess:

RewriteEngine Off
__________________
Follow me on Twitter! http://twitter.com/mrw
Reply With Quote
  #3  
Old 05-24-2008, 07:05 AM
paradigm's Avatar
paradigm paradigm is offline
Hatchling Croc
 
Join Date: May 2008
Posts: 5
Default Re: Fascinating problem with .htaccess and addon domain

Thanks for the suggestion, but I tried it and it didn't work. In fact the .htaccess in the subdirectory seems to be ignored. If I delete .htaccess in the root directory, then my website in the subdirectory works. In other words, I think the the server is processing .htaccess in the root directory before it looks at .htaccess in the subdirectory, even thought it's an addon domain and (I think) it should just look at the files in the subdirectory!
Reply With Quote
  #4  
Old 05-24-2008, 02:00 PM
RainbowViper's Avatar
RainbowViper RainbowViper is offline
King Croc
 
Join Date: Mar 2008
Location: St Paul MN
Posts: 814
Default Re: Fascinating problem with .htaccess and addon domain

This may not help, I realize, but I have the same basic setup as you do.

That said, in my subdomain root the .htaccess file overrides the permissions/restrictions in the main domain's .htaccess file.

BUT, any restriction and/or permission in the root domain's .htaccess, must be explicitly overridden by the subdomain's .htaccess, by using the same command and "toggling" the setting as necessary.

Disclaimer: That may not be a COMPLETE answer, but it's what I've found to be the case in MY setup.

RV
Reply With Quote
  #5  
Old 05-26-2008, 09:45 AM
paradigm's Avatar
paradigm paradigm is offline
Hatchling Croc
 
Join Date: May 2008
Posts: 5
Default Re: Fascinating problem with .htaccess and addon domain

Hey thanks a lot for replying. However, it doesn't work in my case. As a test, if I delete the .htaccess in the public_html root, then the web site in the subdirectory works correctly! I am going to try to raise this issue with support and see if they can help.

Thanks
Reply With Quote
  #6  
Old 05-27-2008, 08:37 AM
paradigm's Avatar
paradigm paradigm is offline
Hatchling Croc
 
Join Date: May 2008
Posts: 5
Default Re: Fascinating problem with .htaccess and addon domain

FYI, I just figured it out. RV, your advice did work after all! I had some other redirects in my .htaccess file in the root directory (I didn't post them because I thought they were irrelevant.) I decided to simplify things and found out that you are right about commands in the .htaccess overriding if you issue the same command in the opposite direction. Slapshotw, Your first suggestion of just turning off the rewrite engine worked after all!

Thanks a bunch!

Last edited by paradigm; 05-27-2008 at 08:40 AM.
Reply With Quote
  #7  
Old 05-27-2008, 08:45 AM
paradigm's Avatar
paradigm paradigm is offline
Hatchling Croc
 
Join Date: May 2008
Posts: 5
Default Re: Fascinating problem with .htaccess and addon domain

For anyone who is interested, I finally found the relevant portion in the Apache tutorial:

The configuration directives found in a .htaccess file are applied to the directory in which the .htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree. And those, in turn, may have overridden directives found yet higher up, or in the main server configuration file itself.

(http://httpd.apache.org/docs/2.0/howto/htaccess.html)
Reply With Quote
  #8  
Old 05-27-2008, 01:02 PM
RainbowViper's Avatar
RainbowViper RainbowViper is offline
King Croc
 
Join Date: Mar 2008
Location: St Paul MN
Posts: 814
Default Re: Fascinating problem with .htaccess and addon domain

You're welcome. Glad I could help.
It mystified me, too, until Support (here, I think, may have been my reseller elsewhere) told me about the "flow-down" into subdirectories, regardless of whether that subdirectory was itself a Subdomain.
RV
Reply With Quote
  #9  
Old 09-01-2009, 02:04 AM
Alejandro's Avatar
Alejandro Alejandro is offline
Hatchling Croc
 
Join Date: Aug 2009
Location: Mexico City, MX
Posts: 6
Default Re: Fascinating problem with .htaccess and addon domain

The use of .htaccess files can be disabled completely by setting the AllowOverride directive to none:

Code:
AllowOverride None
So you might have .htaccess files several directories up, but once they hit this file for the directory you have it in, directives will no longer propagate.
Reply With Quote
  #10  
Old 04-07-2010, 01:43 PM
ExpiredSoon ExpiredSoon is offline
Hatchling Croc
 
Join Date: Apr 2006
Posts: 10
Default Re: Fascinating problem with .htaccess and addon domain

Quote:
Originally Posted by Alejandro View Post
The use of .htaccess files can be disabled completely by setting the AllowOverride directive to none:

Code:
AllowOverride None
So you might have .htaccess files several directories up, but once they hit this file for the directory you have it in, directives will no longer propagate.
When I do this in a subdir .htaccess file, I get Server error 500 in the browser and this in the error log:
/path/to/subdir/.htaccess: AllowOverride not allowed here

Any suggestions? This directive inheritance is killing me right now!
Reply With Quote
  #11  
Old 04-07-2010, 04:39 PM
kompreszor's Avatar
kompreszor kompreszor is offline
Swamp Croc
 
Join Date: Jun 2007
Location: Pennsylvania, USA
Posts: 330
Default Re: Fascinating problem with .htaccess and addon domain

AllowOver is not useable in a .htaccess file, you can only use it in <Directory> and no place else. You could try something like RewriteCond %{REQUEST_URI} !subdomain.com or maybe the %{THE_REQUEST} would be better.
__________________
“There is a principle which is a bar against all information, which is proof against all arguments and which cannot fail to keep a man in everlasting ignorance—that principle is contempt prior to investigation.”
—Herbert Spencer
Reply With Quote
  #12  
Old 04-07-2010, 08:17 PM
ExpiredSoon ExpiredSoon is offline
Hatchling Croc
 
Join Date: Apr 2006
Posts: 10
Default Re: Fascinating problem with .htaccess and addon domain

Quote:
Originally Posted by kompreszor View Post
AllowOver is not useable in a .htaccess file, you can only use it in <Directory> and no place else. You could try something like RewriteCond %{REQUEST_URI} !subdomain.com or maybe the %{THE_REQUEST} would be better.
Thank you for replying kompreszor

I have about 20 RedirectPermanent lines in my root htaccess file, for redirecting only SOME .html files to their .php replacement, which are being inherited by the subdom one directory path lower (/subdomain). Unfortunately the subdomain and the root domain contain like-named files and this is causing redirects from subdomain.com/test.html to root.com/test.php. HG support recommended I start with a fresh htaccess file, replacing individual RedirectPermanent lines with individual RewriteRule lines. Again, note that I am not redirecting ALL .html to .php - that would be much more simple. What's more, Apache documentation recommends using Redirect for per-file use rather than RewriteRule but I don't suppose they figured this would happen.

I have not yet found a way to rewrite just some files of the root all while not touching the subdom...
Reply With Quote
  #13  
Old 04-07-2010, 08:39 PM
ExpiredSoon ExpiredSoon is offline
Hatchling Croc
 
Join Date: Apr 2006
Posts: 10
Default Re: Fascinating problem with .htaccess and addon domain

ok, I fixed it. I need to finish editing before I post the fix...
Reply With Quote
  #14  
Old 04-07-2010, 09:46 PM
ExpiredSoon ExpiredSoon is offline
Hatchling Croc
 
Join Date: Apr 2006
Posts: 10
Default Re: Fascinating problem with .htaccess and addon domain

Here's what worked:
#enable rewrite engine
RewriteEngine on

#rewrite to root path
RewriteBase /

#Following line is the old method
#RedirectPermanent /about.html http://www.root.com/about.php

#Following line is the new method
RewriteRule ^about\.html$ about.php [R,L]

____ EOF ____

.htaccess file in subdomain path (/public_html/subdomain.com/) looks like this:

RewriteEngine off

___ EOF ___

That's it! It was irritating because I would make a change to the htaccess and it would work, then stop working later without making any new changes. Finally I realized that there was something with Firefox caching or something, because it worked fine in IE which hadn't been to either site before.
Reply With Quote
  #15  
Old 04-08-2010, 10:02 AM
mp3 mp3 is offline
Junior Croc
 
Join Date: Dec 2007
Posts: 167
Default Re: Fascinating problem with .htaccess and addon domain

One thing that can really simplify this whole mess is to create your subdomains/add-on domains in a directory above public_html/

This also prevents people from accessing your subdomain/add-on domain through your main domain.

Example:
example.com/mysubdomain
or
example.com/myaddondomain
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Addon Domain Problem Tayrak Shared Hosting Support 10 05-21-2008 09:32 AM
Redirect an addon domain to another addon domain? kitandpup Pre-Sales Questions 1 04-17-2008 05:45 PM
subdomain of addon domain in addon directory, is it possible ? Hadoken Shared Hosting Support 16 03-16-2008 06:39 AM
rewrite / .htaccess problem gobezu Shared Hosting Support 1 03-18-2007 12:24 PM
Addon domain problem, should I wait 24-48 hours before adding new domain? osakka Shared Hosting Support 1 10-01-2006 08:12 PM

All times are GMT -5. The time now is 07:59 AM.