Forum Moderators: phranque

Message Too Old, No Replies

httpd.conf + htaccess + sub directories / sub domains

         

machonemedia

7:56 am on Feb 3, 2012 (gmt 0)

10+ Year Member



Hey,

I've been looking for solutions for days and nothing so far. This is my last hope!

Ok so I have a subdomain @ sub.domain.com where the DocumentRoot is domain.com/sub/ (it's not actually that in the conf, im just making it easy for the example).

I have a bunch of htaccess rewrite rules just to make my URLs nice, like domain.com/contact-us is domain.com/contact_us.php. Done it many times, it's always worked no problem, and currently does work on domain.com.

The problem is domain.com/sub/ (aka, sub.domain.com) isn't allowing htaccess rules. If I enter them directly into my <Directory> directive for the sub directory it works! I need to enable htaccess in the sub directory though, because I don't want to keep updating httpd.conf with this stuff and have to restart the server each time.

AllowOverride All is set in the root directory and my sub directory / sub domain.

AccessFile .htaccess exists above this all.

Here is my VirtualHost for the sub domain:


<VirtualHost MY_IP>
ServerName sub.domain.com
DocumentRoot /home/domain/public_html/sub/
<Directory /home/domain/public_html/sub>
AllowOverride All
</Directory>


I also have this to prevent wildcard subdomains (It's below the above VirtualHost, so shouldn't conflict with it right?)


<VirtualHost MY_IP>
ServerName fail.domain.com
ServerAlias *.domain.com
DocumentRoot /home/domain/public_html/fail/
Redirect 301 / http://domain.com/
</VirtualHost>



My main domain.com VirtualHost has the below (which is above everything else)


<Directory /home/domain/public_html>
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
allow from all
AllowOverride All

... more directives here



See anything wrong? It's all working great except for that 1 sub domain's htaccess, if I enter the .php extension it displays the correct file, just won't enable htaccess for that dir.

Any help would be great.

Thanks.

lucy24

8:48 am on Feb 3, 2012 (gmt 0)

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



Do you mean it isn't recognizing htaccess at all, no way, nohow? Or is it only not recognizing rewrites? Does your htaccess say RewriteEngine On? Unlike most directives, this one isn't inherited. You have to say it over again in each separate .htaccess.

penders

9:55 am on Feb 3, 2012 (gmt 0)

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



Just confirming... this is for an .htaccess file located in domain.com/sub/ ?

machonemedia

5:53 pm on Feb 3, 2012 (gmt 0)

10+ Year Member



Ya this is the top of my file:


Options +FollowSymlinks
RewriteEngine on

RewriteRule ^test$ test.php [nc]

machonemedia

5:57 pm on Feb 3, 2012 (gmt 0)

10+ Year Member



And ya penders, I have an htaccess file in domain.com root and domain.com/sub/, /sub is the only one not working, I only have rewrites but I think all rules aren't working.

The root and /sub htaccess files are the same, it's basically a copy of my main application as a demo, using a different database.

machonemedia

6:05 pm on Feb 3, 2012 (gmt 0)

10+ Year Member



wow it was RewriteEngine On instead of "on" (lowercase) but in my root directory lowercase "on" works, interesting...

lucy24

8:57 pm on Feb 3, 2012 (gmt 0)

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



Ouch, you're right, Apache specifically says lower-case "on" and "off". In Apache it is always safest to assume everything is case-sensitive.* The analogy may be to filenames: your domain can be entered as example.com, EXAMPLE.COM or ExAmPlE.cOm and they will all work. But anything beyond that depends on the server.

... and that's why I wish we had more time to edit posts. If I say something factually incorrect, I don't want someone finding the post in 2017 and doing what it says.


* Regular expressions really are case-sensitive. /d and /w mean the opposite of /D and /W and so on.

g1smd

10:12 pm on Feb 3, 2012 (gmt 0)

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



I always use
RewriteEngine On
in htaccess.

Not seen a situation where it fails, but you never can tell...