How can I delete .html or .php extension in apache with htaccess?



How can I delete .html or .php extension with .htaccess?

Before delete .html or .php extension with htaccess,
First, you must activate rewrite module.



First, you must activate rewrite module.
Ctrl+v this code in terminal.
sudo a2enmod rewrite

If you finished the rewrite activating, You can use htaccess in apache.

Let's delete .html or .php extension!

1.delete .html extension
RewriteEngine On
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{DOCUMENT_ROOT}/$1.html -f 
RewriteRule ^(.+)/?$ /$1.html [L]
(ex) magsty.net/index.html -> magsty.net/index

2.delete .php extension
RewriteEngine On
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.+)/?$ /$1.php [L]
(ex) magsty.net/index.php -> magsty.net/index

3.delete .jsp extension
RewriteEngine On
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{DOCUMENT_ROOT}/$1.jsp -f 
RewriteRule ^(.+)/?$ /$1.jsp [L]
(ex) magsty.net/index.jsp -> magsty.net/index

Thanks for watching and write the commet to rewrite request or question

Post a Comment

0 Comments