Jump to content

[SOLVED] .htaccess rewritecond not being applied


Recommended Posts

Hello everyone.

 

[Made new post because I couldn't move my http://www.phpfreaks.com/forums/index.php/topic,257480.0.html (original) to this child board]

 

I've been trying to stop my site from redirecting when I attempt to log into any folder within the "ftp" folder.

 

URL example:

http://mydomain.com/ftp/private/    or

http://mydomain.com/ftp/public/

 

With what I have set up now, it always attempts to redirect to

http://www.mydomain.com/ftp/private/  or

http://www.mydomain.com/ftp/public/

 

and I end up getting a Forbidden reply.  I get this because the URL is being rewritten with the www. and once it does that, it thinks "the user didn't give me authentication for the first url requested, so I should block access".

 

 

This is what I have....

 

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

If I were to take out all three of those lines altogether, the login works just fine.

 

Any thoughts?

OK - I finally figured out what was happening:

 

1) User requests password-protected folder

2) Server returns standard 401 error

3) Because I had it set to automatically rewrite any URL which didn't start with www, it rewrote the error page as well...which in this case would prevent the user from being able to enter a password - (http://mydomain.com/401.shtml to http://www.mydomain.com/401.shtml)

 

Here's the final htaccess code:

RewriteRule ^(ftp|test)/.*$ - [L]

# If the domain isn't preceded by "www"...
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
# Prevent rewriting of error pages...
RewriteCond %{REQUEST_URI} ![0-9]{3}\.shtml$ [NC]
RewriteRule (.*) http://www\.mydomain\.com/$1 [R=301,NC]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.