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

相關文章
相關標籤/搜索