PHP的mod_rewrite重写模块将.php后缀换成.html
2014-07-15 23:30
351 查看
apache
Rewrite
mod_rewrite的魔力
简单举例:创建三个文件,分别命名为
test.html,test.php和.htaccess
test.html
输入:
<h1>This is the HTML file.</h1>
test.php输入:
<h1>This is the php file.</h1>
.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文件。
输入下一段,
创建无文件后缀名链接
如果你想使你的PHP网站的链接更加简洁易记-或者隐藏文件的后缀名,试试这个:
Rewrite
mod_rewrite的魔力
简单举例:创建三个文件,分别命名为
test.html,test.php和.htaccess
test.html
输入:
<h1>This is the HTML file.</h1>
test.php输入:
<h1>This is the php file.</h1>
.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]
创建无文件后缀名链接
如果你想使你的PHP网站的链接更加简洁易记-或者隐藏文件的后缀名,试试这个:
RewriteRule ^/?([a-z]+)$ $1.php [L]
相关文章推荐
- PHP的mod_rewrite重写模块将.php后缀换成.html
- 【转载】关于PHP的mod_rewrite重写模块技术个人觉得最好的一篇文章
- PHPmod_rewrite重写模块技术
- php 伪静态 (url rewrite mod_rewrite 重写) 本地APACHE支持urlrewrite 本地APACHE支持.htaccess 【转】
- Apache模块详解-mod_rewrite重写模块
- php 伪静态 (url rewrite mod_rewrite 重写)
- php 伪静态 (url rewrite mod_rewrite 重写) 本地APACHE支持urlrewrite 本地APACHE支持.htaccess
- php 伪静态 (url rewrite mod_rewrite 重写)
- apache rewrite thinkphp重写伪静态,加.html后缀
- 深度理解apache 重写模块rewrite_mod,重写不再犯错
- Apache模块 mod_rewrite 及 初级URL重写指南
- php检测apache mod_rewrite模块是否安装的方法
- 在Apache中使用mod_rewrite模块重写URL
- php 伪静态 (url rewrite mod_rewrite 重写)
- php 伪静态 (url rewrite mod_rewrite 重写) 本地APACHE支持urlrewrite 本地APACHE支持.htaccess
- Apache - 模块 - mod_rewrite - RewriteCond - 以域名为重写条件
- php检测apache mod_rewrite模块是否安装的方法
- apache mod_rewrite 模块使用的几个例子
- Xoops URL 重写 | Xoops Mod_Rewrite -- 重写完成篇
- Apache在Windows下使用Mod_rewrite模块