1

So I removed my .php extension with the following code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.php

This works I can access my site like this: www.example.com/page Now I have got the following code

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.php

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

This works too, well kind off. I was testing it out in a sub-folder and now comes the problem:

when I go to www.example.com/sub/page it goes to www.example.com/page/ and there it say's that the folder page isn't found!

Does anyone has a solution?

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Duplicate of http://stackoverflow.com/questions/18751890/php-htaccess-removing-php-extension-from-url http://stackoverflow.com/questions/9963638/htaccess-remove-url-extension-add-trailing-slash http://stackoverflow.com/questions/1337695/remove-php-extension-with-php http://stackoverflow.com/questions/13540353/using-htaccess-to-remove-php-file-extension-from-url http://stackoverflow.com/questions/19904911/remove-php-extension-using-htaccess-methods-keeping-link-juice http://stackoverflow.com/questions/4908122/removing-the-php-extension-with-mod-rewrite – smdrager Feb 18 '14 at 15:54

1 Answers1

0

Have your rules like this:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thank you very much anubhava! This worked indeed! But is it normal that the css doesn't get loaded when I use this methode? – MrBlackDrag0nfly Feb 18 '14 at 15:58
  • Glad to know it worked out. For CSS/JS you should just use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with `http://` or a slash `/`. – anubhava Feb 18 '14 at 16:11