0

I am using the following htaccess code. However this code means that my images or CSS are not loading, on the plus side it means that .php or the trailing / are needed like my client has asked for.

How can I make this work so that the images and the CSS and JS etc load correctly?

I would like the url to look like www.example.com/services or www.example.com/services/

currently google shows up both

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
j08691
  • 204,283
  • 31
  • 260
  • 272
Jon Fuller
  • 305
  • 2
  • 3
  • 9
  • Wait can you clarify - do you want or _not_ want this to eliminate the `.php` extension and add a trailing slash? To get rid of those behaviors, comment out the last 4 lines. It always helps with these questions to post examples of exact URLs which 1) the client requests 2) the file the server should return for that request 3) the URL you want to end up in the client browser after any redirection. – Michael Berkowski Dec 29 '17 at 18:06
  • I have provided examples – Jon Fuller Dec 29 '17 at 18:10

1 Answers1

0
# enforce a trailing-slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

# remove php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L,QSA]

See also

Htaccess: add/remove trailing slash from URL

Remove .php extension with .htaccess

Ben
  • 5,069
  • 4
  • 18
  • 26