單頁面

針對不同服務器、虛拟空間,運行PHP的環境也有所不同,目前主要分(fēn)爲:Nginx、apache、IIS以及其他服務器。下(xià)面分(fēn)享如何去(qù)掉URL上的index.php字符,記得最後要重啓服務器,在管理後台清除緩存哦!
 
【IIS服務器】
在網站根目錄下(xià)有個 web.config 文件,這個文件的作用是重寫URL,讓URL變得簡短,易于SEO優化,以及用戶的記憶。打開(kāi) web.config 文件,在原有的基礎上加以下(xià)代碼片段即可。
<rewrite>
<rules>
<rule name="Imported Rule 1" enabled="true" 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>
 
以下(xià)是某個香港虛拟空間的效果:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="PHP-7.0-7i24.com" />
<remove name="PHP-5.6-7i24.com" />
<remove name="PHP-5.5-7i24.com" />
<remove name="PHP-5.4-7i24.com" />
<remove name="PHP-5.3-7i24.com" />
<remove name="PHP-5.2-7i24.com" />
<add name="PHP-5.4-7i24.com" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="c:php.4php-cgi.exe" resourceType="Either" />
</handlers>
<rewrite>
<rules>
<rule name="Imported Rule 1" enabled="true" 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>
</system.webServer>
</configuration>
 
【Nginx服務器】
在原有的nginx重寫文件裏新增以下(xià)代碼片段:
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
 
【apache服務器】
易優CMS在apache服務器環境默認自動隐藏index.php入口。
如果發現沒隐藏,可以檢查根目錄.htaccess是否含有以下(xià)代碼段:
<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>

如果存在,繼續查看apache是否開(kāi)啓了URL重寫模塊 rewrite_module , 然後重啓服務就行了。