Original link: https://www.cnblogs.com/chq3272991/p/5757673.html
The official introduction is like this: http://www.kancloud.cn/thinkphp/thinkphp5_quickstart/145250
The entry file in the URL address can be removed index.php
, but the rewrite rules of the WEB server need to be additionally configured.
For Apache
example, you need to add a file at the same level as the entry file .htaccess
(the official file comes with it by default), the content is as follows:
<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>
Then you can use the following URL address to access
http://tp5.com/index/index/index
http://tp5.com/index/index/hello
If the apache
version you are using cannot be hidden normally using the above method index.php
, you can try to configure the .htaccess
file in the following way:
<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>
但是还是不行,查到这么一篇文章(http://bbs.php100.com/simple/?t300372.html):
Apache Rewrite 拟静态配置
1、mod_rewrite 简介和配置
Rewirte主要的功能就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则
表达式规范。平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等
如一个普通访问地址为
*/php100.php?id=2
可以转成:
*/PHP100_2.html
或转成:
*/PHP100_2/
Apache配置:
支持httpd.conf 配置和目录 .htaccess配置
启用rewrite
# LoadModule rewrite_module modules/mod_rewrite.so
去除前面的 #
LoadModule rewrite_module modules/mod_rewrite.so
启用.htaccess
AllowOverride None 修改为: AllowOverride All
2、mod_rewrite 规则的使用
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.php100.com [NC]
RewriteRule ^/(.*) http://www.php100.com/ [L]
启动rewrite引擎 判断主机 跳转到
RewriteEngine on
RewriteRule ^/test([0-9]*).html$ /test.php?id=$1
RewriteRule ^/new([0-9]*)/$ /new.php?id=$1 [R]
3、mod_rewrite 规则修正符
1) R 强制外部重定向
2) F 禁用URL,返回403HTTP状态码。
3) G 强制URL为GONE,返回410HTTP状态码。
4) P 强制使用代理转发。
5) L 表明当前规则是最后一条规则,停止分析以后规则的重写。
6) N 重新从第一条规则开始运行重写过程。
7) C 与下一条规则关联
如果规则匹配则正常处理,以下修正符无效
8) T=MIME-type(force MIME type) 强制MIME类型
9) NS 只用于不是内部子请求
10) NC 不区分大小写
11) QSA 追加请求字符串
12) NE 不在输出转义特殊字符 \%3d$1 等价于 =$1
-----------------------------------------------------------------------------
也就是最后还要补充这么处理:
Remove the # in front of #LoadModule rewrite_module modules/mod_rewrite.so,
then change the permission AllowOverride None to AllowOverride All, restart apache