Removing extensions and trailing slashes in web urls:


/ Published in: Apache
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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]

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.