PHP的mod_rewrite重写模块将.php后缀换成.html_PHP

WBOY
Release: 2016-05-30 08:47:36
Original
1078 people have browsed it

apache Rewrite

mod_rewrite的魔力
简单举例:创建三个文件,分别命名为 test.html,test.php和.htaccess
test.html 输入:

This is the HTML file.


test.php输入:

This is the php file.


.htaccess输入:
RewriteEngine on
RewriteRule ^/?test\.html$ test.php [L]
将以上三个文件放test测试文件夹下,在浏览器录入:
http://www.example.com/test/test.html
在浏览器中将 www.example.com替换成你自己的域名。如果运行结果显示“This is the PHP file”,那么运行成功,如果结果显示“This is the Html file”,那么肯定是哪里出了问题,请你再仔细检查下。
如果你测试成功,你是否发现了我们录入了test.html的文件名,确执行了test.php文件,是的,你已经初识了mod_rewrite的神奇。

在想要将.php后缀换成.html的目录下创建并命名为.htaccess文件。

输入下一段,

RewriteEngine on

RewriteRule ^/?([a-zA-Z0-9]+)\.html$ $1.php [L]

<strong>创建无文件后缀名链接</strong>
如果你想使你的PHP网站的链接更加简洁易记-或者隐藏文件的后缀名,试试这个:
Copy after login
RewriteRule ^/?([a-z]+)$ $1.php [L]
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!