Tp中Url的重写。
任务1:去掉index.php
情景1:
使用版本:TP5完整版
下载地址:http://www.thinkphp.cn/download/1278.html
环境Apache
1.编辑httpd.conf
解开注释 LoadModule rewrite_module modules/mod_rewrite.so
修改AllowOverride
<Directory "/usr/local/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
2.修改 public/.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]
</IfModule>
情景2:tp3.2
tp3.2中URL默认状态是
http://localhost/index.php/home/index/index
修改httpd.conf,修改内容同上,即可访问
http://localhost/home/index/index(它无需去掉public)
情景3:nginx+tp5
修改nginx.conf
#root写如public,让/后面直接连接index.php
root html/public;
index index.php index.html index.htm;
#根部分改写,将/后内容当成$1放在s=后面
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?s=/$1 last;
}
}
#php部分不变
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
任务2:去掉public
Apache 修改DocumentRoot,指定public文件夹。