Forum Moderators: phranque

Message Too Old, No Replies

.htaccess not working in sub directories

         

rumbletom

4:53 pm on Sep 17, 2010 (gmt 0)

10+ Year Member



Hi,

I'm new to Apache and .htaccess. I am using a godaddy virtual host.

I have an .htaccess file in public_html which works fine. But one created in a sub directory for password protection doesn't work. The page loads as usual.

I have edited the httpd.conf to point at the directory where the new .htaccess file is -

<Directory "/public_html/celeb/public_html/private/albums">
Options All
AllowOverride All
</Directory>

but this does not help.

Any help would be great. Thanks.

phranque

8:01 am on Sep 18, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], rumbletom!

does mod_auth work in the document root directory's .htaccess?
have you done all the usual things to insure it's not a cache problem somewhere?

otherwise i would try some other directive in that file to make sure it's not just a problem with mod_auth or that directory.
perhaps you could temporarily try specifying a custom 404 page in the subdirectory's .htaccess and see if that is working first.

jdMorgan

5:22 pm on Sep 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure to delete your browser cache after making any changes to server-side code or configuration. Also, the login page should be marked as non-cacheable using Apache mod_headers and/or mod_expires.

Jim

rumbletom

1:26 pm on Sep 20, 2010 (gmt 0)

10+ Year Member



Hi and thank you chaps.

mod_auth does work in the document root directory's .htaccess.

A custom 404 page in the subdirectory does not. A 404 page does appear but not the custom one specified by the .htaccess in the subdirectory.

I have deleted the browser cache, restarted the server, and use the script that comes with the gallery software (Gallery2) to delete all it's caches.

I'm afraid I don't know how to use Apache mod_headers and/or mod_expires. I have been searching but it's probably best I take a break and see if what I have already written helps.

Tom.

rumbletom

3:12 pm on Sep 20, 2010 (gmt 0)

10+ Year Member



extra info -

this is the code used in the .htaccess in root

# BEGIN Url Rewrite section
# (Automatically generated. Do not edit this section)
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
RewriteCond %{REQUEST_URI} !/main\.php$
RewriteRule . - [L]

RewriteCond %{QUERY_STRING} view=core.DownloadItem
RewriteCond %{HTTP:Referer} !^[a-zA-Z0-9\+\.\-]+://celebrity-hq.co.uk/ [NC]
RewriteCond %{HTTP:Referer} !^$
RewriteRule . /main.php [F,L]
RewriteCond %{QUERY_STRING} g2_view=core.DownloadItem
RewriteCond %{QUERY_STRING} g2_itemId=([0-9]+)
RewriteCond %{HTTP:Referer} !^[a-zA-Z0-9\+\.\-]+://celebrity-hq.co.uk/ [NC]
RewriteCond %{HTTP:Referer} !^$
RewriteRule . /main.php?g2_view=rewrite.DownloadItem&g2_itemId=%1 [L]
RewriteCond %{THE_REQUEST} /sitemap(\?.|\ .)
RewriteCond %{REQUEST_URI} !/main\.php$
RewriteRule . /main.php?g2_view=sitemap.Sitemap [QSA,L]
RewriteCond %{THE_REQUEST} /admin/(\?.|\ .)
RewriteCond %{REQUEST_URI} !/main\.php$
RewriteRule . /main.php?g2_view=core.SiteAdmin [QSA,L]
RewriteCond %{THE_REQUEST} /d/([0-9]+)-([0-9]+)/([^/?]+)(\?.|\ .)
RewriteCond %{REQUEST_URI} !/main\.php$
RewriteRule . /main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3 [QSA,L]
RewriteCond %{THE_REQUEST} /rss/([^\/\?]+)(\?.|\ .)
RewriteCond %{REQUEST_URI} !/main\.php$
RewriteRule . /main.php?g2_view=rss.Render&g2_name=%1 [QSA,L]
RewriteCond %{THE_REQUEST} /srss/([0-9]+)(\?.|\ .)
RewriteCond %{REQUEST_URI} !/main\.php$
RewriteRule . /main.php?g2_view=rss.SimpleRender&g2_itemId=%1 [QSA,L]
RewriteCond %{THE_REQUEST} /v/([^?]+)(\?.|\ .)
RewriteCond %{REQUEST_URI} !/main\.php$
RewriteRule . /main.php?g2_path=%1 [QSA,L]
RewriteCond %{THE_REQUEST} /([^?]+)(\?.|\ .)
RewriteCond %{REQUEST_URI} !/main\.php$
RewriteRule . /main.php?g2_view=rewrite.FileNotFound [QSA,L]
</IfModule>

# END Url Rewrite section

# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName celebrity-hq.co.uk
AuthUserFile /public_html/celeb/public_html/_vti_pvt/service.pwd
AuthGroupFile /public_html/celeb/public_html/_vti_pvt/service.grp


this is the code used in the subdirectory.

AuthUserFile /public_html/celeb/data/.htpasswd

AuthName MEMBERS

AuthType Basic



<Limit GET POST>

require valid-user

</Limit>

rumbletom

5:22 pm on Sep 20, 2010 (gmt 0)

10+ Year Member



Sorry for getting into a conversation with myself but I have worked some things out. The problem seems to lie with the gallery software I am using. I have been able to password protect a folder I created, so as far as .htaccess goes it is now working. I will take further questions to the forum at G2 Gallery.
Thanks very much for your help.

jdMorgan

5:46 pm on Sep 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Comment: Your code will be much more efficient if you re-arrange the RewriteConds in your first rule so that the "exists" checks are only done when needed. Your hard drives will likely last longer, too...

RewriteCond %{REQUEST_URI} !/main\.php$
RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]

Jim

rumbletom

6:43 pm on Sep 20, 2010 (gmt 0)

10+ Year Member



Thanks for that Jim. I will attempt to find and change the code correctly as soon as I am finished with the first 'to do'. Otherwise, as I know from experience, I may end up in a very dark place..

Regards Tom.