Trying to add trailing slash with htaccess, results in a absolute path
Posted
by
Fredrik
on Stack Overflow
See other posts from Stack Overflow
or by Fredrik
Published on 2011-01-03T00:20:54Z
Indexed on
2011/01/03
1:54 UTC
Read the original article
Hit count: 524
What I'm trying to achive is to have all urls on my page look like http://domain.com/page/
, no extensions, but a trailing slash. If a user happends to write http://domain.com/page
or http://domain.com/page.php
it will redirect to the first url. After some googling i found this code, and it's close to working, but when you leave out the trailing slash in your request the url becomes something like http://domain.com/Users/"..."/page/
and therefor returns a 404.
My .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !(.*)/$
RewriteRule (.*)/$ $1.php [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]
I've been trying to add an additional rule but I really don't get any of this and I haven't been able to find any answers.
© Stack Overflow or respective owner