您的位置:首页 > 编程语言 > PHP开发

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

2017-11-16 17:57 295 查看

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项目部署。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息