這篇文章主要介紹了PHP各環境下的偽靜態配置,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。
一、Apache的偽靜態配置
1、網站根目錄下需要有 .htaccess 文件,沒有則自己創建一個,內容
- <IfModule mod_rewrite.c>
- RewriteEngine on
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
- </IfModule>
如果你的apache是fastcgi模式下,則需要修改
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
替換成
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
2、在apache的配置文件httpd.conf中查找 : LoadModule rewrite_module modules/mod_rewrite.so 將前面的#去掉,假如沒有這段內容,則需要手動加上
3、在apache的配置文件httpd.conf中查找所有的 AllowOverride None,將 None 都替換成 All . 保存文件 并重啟apache服務。
二、Nginx的偽靜態配置
找到nginx的配置文件 nginx.conf, 在里面的 server{ } 里增加以下內容
- location / {
- if (!-e $request_filename) {
- rewrite ^(.*)$ /index.php?s=$1 last;
- break;
- }
- }
重啟nginx即可生效
三、IIS的偽靜態配置
如果你的服務器環境支持ISAPI_Rewrite的話,可以配置httpd.ini文件,添加下面的內容:
RewriteRule (.*)$ /index/.php/?s=$1 [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>
新聞熱點
疑難解答