gmaestro
gmaestro

Reputation: 339

Htaccess change php extension

How I can show on browser url my php file without .php extension SO:

instead home.php , just home

How to do that with .htaccess, what I need to write in this file?

Upvotes: 2

Views: 99

Answers (2)

anubhava
anubhava

Reputation: 786289

put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

Upvotes: 1

ooo
ooo

Reputation: 1627

You can achieve this like that:

RewriteEngine On
RewriteRule ^([^/]*)$ /$1.php [L]

Upvotes: 1

Related Questions