当前位置: 动力学知识库 > 问答 > 编程问答 >

Using .htaccess, how can i change file extension at run time

问题描述:

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.

网友答案:

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]
网友答案:

There is a really easy way with .htaccess:

RewriteEngine on  
RewriteBase /

RewriteCond %{THE_REQUEST} (.*)\.php  
RewriteRule ^(.*)\.php $1.html [R=301,L] 
分享给朋友:
您可能感兴趣的文章:
随机阅读: