apache/htaccess: how to avoid redirecting dir to dir/

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

apache/htaccess: how to avoid redirecting dir to dir/

Post by Apollo »

Suppose I have a subdir foo/ on my website.
If I go to http://www.example.com/foo Apache will automatically redirect me (by giving me a 301 Moved Permanently) to http://www.example.com/foo/ (with the slash) and get whatever is inside the foo/ dir (if anything and visible, or an error otherwise).

Now, is there also some .htaccess option or smart rewrite rule that will avoid this?
Well, i could do RewriteRule ^foo$ bar of course, but I mean in general, i.e. for any subdir?

(btw I don't really need this in a practical situation, but stumbled upon this while struggling with another problem, and just wondering)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: apache/htaccess: how to avoid redirecting dir to dir/

Post by requinix »

DirectorySlash is what you're looking for, but I'd advise against it unless someone really knows what they're doing.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: apache/htaccess: how to avoid redirecting dir to dir/

Post by Apollo »

Thanks tasairis, that's it!
Post Reply