Home > php教程 > php手册 > body text

PHP study notes: Writing pseudo-static rules

WBOY
Release: 2016-10-12 09:50:13
Original
1322 people have browsed it

这里以阿帕奇为服务器软件,直接上案例:

1.把index.html重定向到index.php

<span style="font-size: 18px;"><span style="color: #000000;">RewriteEngine On

Options </span>-<span style="color: #000000;">Indexes
</span><span style="color: #000000;">
ReWriteRule </span>^index.html$  /index.php  [NC]</span>
Copy after login

效果:访问www.test.com/index.html效果等于www.test.com/index.php

 

2.把index重定向到index.php

<span style="font-size: 18px;"><span style="color: #000000;">RewriteEngine On

Options </span>-<span style="color: #000000;">Indexes
</span><span style="color: #000000;">
ReWriteRule </span>^index$  /index.php  [NC]</span>
Copy after login

效果:访问www.test.com/index效果等于www.test.com/index.php

 

3.根目录下的PHP文件,用html后缀也能访问

写法1:

<span style="font-size: 18px;"><span style="color: #000000;">RewriteEngine On
Options </span>-<span style="color: #000000;">Indexes

ReWriteRule </span>^([a-zA-Z0-9_]{1,})\.html$  /$1.php  [NC]</span>
Copy after login

效果:   访问www.test.com/index.html效果等于www.test.com/index.php

    访问www.test.com/abc.html效果等于www.test.com/abc.php

 4.根目录下的php文件,直接访问文件名效果一样

<span style="font-size: 18px;"><span style="color: #000000;">RewriteEngine On
Options </span>-<span style="color: #000000;">Indexes

ReWriteRule </span>^([a-zA-Z0-9_]{1,})$  /$1.php  [NC]</span>
Copy after login

效果:   访问www.test.com/index效果等于www.test.com/index.php

    访问www.test.com/abc效果等于www.test.com/abc.php

 

5.访问文件名+html效果等效后缀为php的文件

 

<span style="color: #000000;">RewriteEngine On
Options </span>-<span style="color: #000000;">Indexes

RewriteRule </span>^/?([a-z/]+)\.html$ $1.php [NC]
Copy after login

 

效果:  

    访问www.test.com/index.html效果等于www.test.com/index.php

    访问www.test.com/abc/abc.html效果等于www.test.com/abc/abc.php

 

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 Recommendations
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!