Home php教程 php手册 PHP study notes: Writing pseudo-static rules

PHP study notes: Writing pseudo-static rules

Oct 12, 2016 am 09:50 AM

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

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

 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)