0

Below is my current htaccess file. It's set up to allow for no extensions and to 301.php and .htm to no extension.

I also need to add trailing slashes whenever there isn't one. There are plenty of topics on here answering that question but I can't seem to add it without messing something else up.

RewriteEngine On


# check to see if the request is for a PHP file and rewite to no extension:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]


# redirect PHP or HTM to no extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.(php|htm?)
RewriteRule ^ /%1 [L,R=301]
sarah3585
  • 637
  • 13
  • 37

1 Answers1

1

Have it this way:

RewriteEngine On

# redirect PHP or HTM to no extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.(php|html?) [NC]
RewriteRule ^ /%1/ [L,R=301]

## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]    

# check to see if the request is for a PHP file and rewite to no extension:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643