Home  >  Article  >  php教程  >  开启PHP的伪静态,开启PHP伪静态

开启PHP的伪静态,开启PHP伪静态

WBOY
WBOYOriginal
2016-06-13 08:48:40809browse

开启PHP的伪静态,开启PHP伪静态

1.检测Apache是否支持mod_rewrite
通过php提供的phpinfo()函数查看环境配置,通过Ctrl+F查找到“Loaded Modules”,其中列出了所有
apache2handler已经开启的模块,如果里面包括“mod_rewrite”,则已经支持,不再需要继续设置。


如果没有开启“mod_rewrite”,则打开目录 您的apache安装目录“/apache/conf/” 下的 httpd.conf 文
件,通过Ctrl+F查找到“LoadModule rewrite_module”,将前面的”#”号删除即可。


如果没有查找到,则到“LoadModule” 区域,在最后一行加入“LoadModule rewrite_module modules/mod_rewrite.so”(必选独占一行),然后重启apache服务器即可。

2.在httpd.conf中配置虚拟主机
# Virtual hosts 启用虚拟主机
Include conf/extra/httpd-vhosts.conf

3.httpd_vhosts.conf文件中,配置相应的选项.详细讲解

    DocumentRoot "C:/myenv/apache/htdocs/static3"
    ServerName www.hsp.com
   
#Deny from All 403错误提示
Allow from All
#如果文件目录在apache目录外面,注释掉optinos 则,不能列表.
options +Indexes
#下面这个表示可以去读取 .htaccess文件,也可以直接在虚拟主机中配置.
Allowoverride All
RewriteEngine On
RewriteRule news-id(\d+).html$ error.php?id=$1
#这里可以设置多个重写的规则
#RewriteRule news-id.html$ error.php
   

 

4.在相应的目录下编写.htaccess 重写规则
   例子:

RewriteEngine On
RewriteRule news-id(\d+).html$ show.php?id=$1
#这里可以设置多个重写的规则
#RewriteRule news-id.html$ error.php

 
如果在linux下可以直接创建,
如果是在windows平台下,用记事本创建一个文件,比如abc.txt,然后另存
为 .htaccess文件即可

5.重写规则,也可以直接在配置虚拟主机的段配置.

Statement:
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