0

I'm trying to remove page extensions and i used this methods:

Method 1:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

Method 2:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]

But with these methods I can only remove php extension! How can i remove both html and php extensions?

Ne ro
  • 33
  • 1
  • 7
  • https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/ –  Jan 16 '18 at 16:17

2 Answers2

0

You can use this

 RewriteEngine on

# remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ $1.php [L]

#remove .html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/?$ $1.html [L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
-1

Simply use this:

RewriteEngine on
RewriteRule ^(.*).html$ http://your-domain.tld/$1 [R=301,L]
RewriteRule ^(.*).php$  http://your-domain.tld/$1 [R=301,L]

For more information see: https://htaccessbook.com/add-remove-change-file-extensions-htaccess/