ThinkPHP的URL重写方法

前言:phpstudy在apache模式下重写urlphp

1.打开httpd.conf配置文件,ctrl+F 找到:mod_rewrite.so ,去掉前面的#号apache

2.AllowOverride None 将None改成 All ,注意这是第二个AllowOverride 出现的地方修改成All("D:/phpStudy/Apache/cgi-bin")ide

3.把下面的内容保存为.htaccess文件放到入口文件的同级目录下网站

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L] 
</IfModule>

4.重启Apache从新访问url

 

若:spa

发现出现了:No input file specified..net

5.解决办法以下:code

在Fastcgi模式下,php不支持rewrite的目标网址的PATH_INFO的解析,当咱们的 ThinkPHP运行在URL_MODEL=2时,就会出现 No input file specified.的状况, 
这时能够修改网站目录的.htaccess文件: 
将 RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 
改成 RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]blog

或把RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]修改成ci

RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 

以上代码亲测过,没问题

参考连接:https://blog.csdn.net/wlonging/article/details/53613173

相关文章
相关标签/搜索