Reputation:
I want to make a website with PHP, but don't want to show the extension like http://example.com/index.php
, i have that index.php
file but want to show only index.html
, may be .html
something else..
I don't know how to do, please help me.
Upvotes: 1
Views: 914
Reputation: 786289
You can use these 2 rules in your site root .htaccess:
RewriteEngine on
# To externally redirect /dir/foo.php to /dir/file.html
RewriteCond %{THE_REQUEST} \s/+(.+)\.php[\s?] [NC]
RewriteRule ^ /%1.html [R=301,L]
# To internally rewrite /dir/file.html to /dir/file.php
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+)\.html$ $1.php [L]
Upvotes: 2
Reputation: 51
There is a really easy way with .htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
Upvotes: 2