PHP项目部署-开启rewrite(伪静态)

来源:互联网 发布:绿盾软件 编辑:程序博客网 时间:2024/06/06 03:27

TIPS:作者所用环境为2.4.25(Unix),不同版本配置应该会有所差异。

1、httpd.conf配置。

#LoadModule rewrite_module modules/mod_rewrite.so  去掉#

TIPS:开启mod_rewrite即可实现Apache的伪静态功能。

2、httpd.vhosts.conf配置。

<VirtualHost *:80>    ServerName www.xxx.com    DocumentRoot /webdata/xxx    <Directory  "/webdata/xxx/">        Options +Indexes +Includes +FollowSymLinks +MultiViews        AllowOverride All    </Directory></VirtualHost>

一定要配置为:AllowOverride All

此时,我的PHP项目已经开启了rewrite模块,可以使用PHP框架路由模式来进行其指定的路由访问。

3、隐藏index.php入口文件:
项目入口文件index.php的同级目录配置.htaccess。内容如下:

<IfModule mod_rewrite.c>  Options +FollowSymlinks -Multiviews  RewriteEngine On  RewriteCond %{REQUEST_FILENAME} !-d  RewriteCond %{REQUEST_FILENAME} !-f  #RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]  RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]</IfModule>

此时已完成PHP项目部署。