框架中的URL存取過程
URL設計規格
#6.0的URL存取受路由影響,如果在沒有定義或匹配路由的情況下(並且沒有開啟強制路由模式的話),則是基於:
http://serverName/index.php(或者其它入口文件)/控制器/操作/参数/值…
如果開啟自動多應用模式的話,URL一般是
http://serverName/index.php/应用/控制器/操作/参数/值...
普通模式的URL訪問不再支持,但參數可以支援普通方式傳值
如果不支援PATHINFO的伺服器可以使用相容模式存取如下:
http://serverName/index.php?s=/控制器/操作/[参数名/参数值...]
URL重寫規則
#可以透過URL重寫隱藏應用程式的入口文件index.php(也可以是其它的入口文件,但URL重寫通常只能設定一個入口文件),下面是相關伺服器的設定參考:
[ Apache ]
1.httpd.conf設定檔中載入了mod_rewrite.so模組
2.AllowOverride None 將None改為All
3.把下面的內容儲存為.htaccess檔案放到應用程式入口檔案的同級目錄下
<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/ [QSA,PT,L] </IfModule>
# [ IIS ](windows)
如果你的伺服器環境支援ISAPI_Rewrite的話,可以設定httpd.ini文件,加入下面的內容:
RewriteRule (.*)$ /index\.php\?s= [I]
在IIS的高版本下面可以設定web. Config,在中間加入rewrite節點:
<rewrite> <rules> <rule name="OrgPage" stopProcessing="true"> <match url="^(.*)$" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="^(.*)$" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" /> </rule> </rules> </rewrite>
[ Nginx ]
在Nginx低版本中,是不支援PATHINFO的,但是可以透過在Nginx.conf中設定轉送規則實作:
location / { // …..省略部分代码 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/ last; } }
其實內部是轉送到了ThinkPHP提供的相容URL,利用這種方式,可以解決其他不支援PATHINFO的WEB伺服器環境。