1

I have managed to successfully remove the .php extension to my files, but am having problems adding a trailing slash to my pages. Sorry if this has been covered before, have searched everywhere but can't find anything that will work.

Any help would be much appreciated, my ht.access currently looks like this:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/index
RewriteRule ^(.*)index$ http://www.mywebsite.co.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^mywebsite.co.uk [NC]
RewriteRule (.*) http://www.mywebsite.co.uk/$1 [R=301,L]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php?\ HTTP
    RewriteRule (.+)\.php?$ http://www.mywebsite.co.uk/$1 [R=301,L]
    RewriteCond %{REQUEST_fileNAME} !-d
    RewriteCond %{REQUEST_fileNAME}\.php -f
    RewriteRule ^(.*)$ $1.php

The first part is just to redirect the home page to one version. The indented part is what I used to remove the .php from the filenames. Just need to add a trailing slash to files that don't already have one.

netiul
  • 2,737
  • 2
  • 24
  • 29
Darren
  • 11
  • 2
  • this is the code I have been using at the bottom of the .htaccess to try and add the slash: RewriteBase / RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+[^/])$ $1/ [R] – Darren Nov 04 '11 at 13:50

1 Answers1

1
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php 
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://www.mywebsite.co.uk/$1 [R=301,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://www.mywebsite.co.uk/$1/ [R=301,L,QSA]

Use this in .htaccess file remove your code!

user3508453
  • 878
  • 3
  • 14
  • 24