php 去掉Url里的 index.php
2016-02-25 17:24
706 查看
php项目中,为了访问链接的友好性及SEO优化,我们经常需要为访问页面配置一个短链接,并把index.php去掉。
php所用的web服务器通常为:nginx或者apache。下面分别说一下两种服务器的不同配置方法
NGINX 配置:
1、打开nginx配置文件:/usr/local/nginx/conf/nginx.conf
2、修改文件,有两种语法
A:
B:
如果根目录为二级目录,则需要做对应修改:
A:
B:
3、检查Nginx是否有语法错误,无错误则重启
Apache 配置:
1、httpd.conf配置文件中加载了mod_rewrite.so模块
2、修改httpd.conf配置文件:
AllowOverride None 中将None改为 All
(注意其他地方的AllowOverride也统统设置为ALL)
3、.htaccess文件必须放到跟目录下
.htaccess 文件内容
php所用的web服务器通常为:nginx或者apache。下面分别说一下两种服务器的不同配置方法
NGINX 配置:
1、打开nginx配置文件:/usr/local/nginx/conf/nginx.conf
2、修改文件,有两种语法
A:
location / { try_files $uri $uri/ /index.php?q=$uri&$args; }
B:
location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$uri&$args; } }
如果根目录为二级目录,则需要做对应修改:
A:
location /cn/ { try_files $uri $uri/ /cn/index.php?q=$uri&$args; }
B:
location /cn/ { if (!-e $request_filename) { rewrite ^/cn/(.*)$ /cn/index.php?q=$uri&$args; } }
3、检查Nginx是否有语法错误,无错误则重启
#检查是否有语法错误 /usr/local/nginx/sbin/nginx -t #重启nginx /usr/local/nginx/sbin/nginx -s reload
Apache 配置:
1、httpd.conf配置文件中加载了mod_rewrite.so模块
#LoadModule rewrite_module modules/mod_rewrite.so 把前面的 # 去掉
2、修改httpd.conf配置文件:
AllowOverride None 中将None改为 All
(注意其他地方的AllowOverride也统统设置为ALL)
AllowOverride none 改 AllowOverride ALL Options None Order allow,deny Allow from all
3、.htaccess文件必须放到跟目录下
.htaccess 文件内容
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
相关文章推荐
- 高通平台手机开发之TP
- PHP之标准类
- PHP基础
- php中的&
- PHP之对象遍历
- Yii中的数据库事务的使用方法小结
- Yii使用find findAll查找出指定字段的实现方法
- PHP基础(命名错误)错误导致的500
- PHP基础(命名错误)错误导致的500
- yii 数据库添加,修改,删除相关操作总结
- yii批量插入数据
- Yii查看(输出)当前页面执行的sql语句
- PHP不借助第三个变量交换值
- 今日分享一点干货。PHP中课程表的实现。
- yii框架
- ntp源码解读(一)
- PHP运算符
- H264码流结构分析和rtp打包结构详解
- ContentProvider是如何实现数据共享的。
- 解决FTP不支持软连接