skip to Main Content

I have a code in my .htaccess file:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /.*.html HTTP/
RewriteRule ^(.*).html$ /$1 [R=301,L] 

It removes .html extension from urls, how do I remove .php as well with the same code?

2

Answers


  1. I am sure there’s a shorter way to solve this out there but in this is how I remove php extension at the moment:

    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule ^(.*)$ $1.php
    

    Update:

    Try this since you would like to main existing code

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /.*.php HTTP/ 
    RewriteRule ^(.*).php$ /$1 [R=301,L]
    
    Login or Signup to reply.
  2. Check this modified rule

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /.*.(php|html|htm) HTTP/
    RewriteRule ^(.*).(php|html|htm)$ /$1 [R=301,L] 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search