Posted By

jefferis on 01/09/16


Tagged

php html rewrite


Versions (?)

Removing extensions and trailing slashes in web urls:


 / Published in: Apache
 

URL: http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

Removing extensions and trailing slashes in web urls: "If you want to remove the .html extension from a html file for example yoursite.com/wallpaper.html to yoursite.com/wallpaper you simply have to alter the last line from the code above to match the filename" Not sure if the middle 2 lines are needed.

  1. RewriteEngine On
  2. RewriteCond %{REQUEST_FILENAME} !-f
  3. RewriteRule ^([^/]+)/$ $1.php
  4. RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
  5.  
  6. RewriteRule ^([^\.]+)$ $1.html [NC,L]
  7. RewriteRule ^([^\.]+)$ $1.htm [NC,L]
  8.  
  9. RewriteCond %{REQUEST_FILENAME} !-f
  10. RewriteCond %{REQUEST_FILENAME} !-d
  11. RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
  12. RewriteRule (.*)$ /$1/ [R=301,L]

Report this snippet  

You need to login to post a comment.