JakeTheSnake3.0 Posted June 22, 2009 Share Posted June 22, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/163243-solved-htaccess-rewritecond-not-being-applied/ Share on other sites More sharing options...
JakeTheSnake3.0 Posted June 27, 2009 Author Share Posted June 27, 2009 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] Quote Link to comment https://forums.phpfreaks.com/topic/163243-solved-htaccess-rewritecond-not-being-applied/#findComment-864851 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.