PDA

View Full Version : .htaccess to add slashes


daemonkin
01-31-2008, 02:17 PM
Hi guys,

Not too sure about .htaccess but giving it a try:

I want to add '/' to end of address if a directory exists. I have googled some help but get the following:


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]


Now I know I have to edit domain.com but do I leave the rest to work its magic? Doing this does make it work and domain.com/dir does not redirect to domain.com/dir/

I have placed the above code in the following:


## production server directives ##
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]
</IfModule>


Any help appreciated

D.

outseeker
02-17-2008, 10:39 PM
On my apache setup, if I type www.address.com/directory it will automatically add the slash if it is a directory. Why is it you wish to do this anyway? Is something not running correctly as it is?

Meltdown
02-23-2008, 02:20 AM
same thing here.

My htaccess states: Options +FollowSymLinks
RewriteEngine on

RewriteRule / index.php?1=$1

and if I type address.com/directory, i get a 404
however if i add a trailing slash, it works (eg address.com/directory/)

So basically, how would I make it so that it doesn't matter if the user types a trailing slash or not.

Meltdown
03-03-2008, 10:34 PM
1. RewriteCond %{REQUEST_FILENAME} !-f
2. RewriteCond %{REQUEST_URI} !(.*)/$
3. RewriteRule ^(.*)$ http://www.domain.com/$1/ [R=301,L]