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?

1
  • alexcican.com/post/… Commented Jan 16, 2018 at 16:17

2 Answers 2

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]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. It works well :)
-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/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.