單頁面

針對不同服務器、虛拟空間,運行PHP的環境也有所不同,目前主要分(fēn)爲:Nginx、apache、IIS以及其他(tā)服務器。下面分(fēn)享如(rú)何去(qù)掉URL上的index.php字符,記得(de)最後要重啓服務器,在管理(lǐ)後台清除緩存哦!
 
【IIS服務器】
在網站(zhàn)根目錄下有個 web.config 文件(jiàn),這個文件(jiàn)的作(zuò)用是重寫URL,讓URL變得(de)簡短(duǎn),易于SEO優化,以及用戶的記憶。打開 web.config 文件(jiàn),在原有的基礎上加以下代碼片段即可(kě)。
<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>
 
以下是某個香港虛拟空間的效果:
<?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重寫文件(jiàn)裡(lǐ)新增以下代碼片段:
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
 
【apache服務器】
易優CMS在apache服務器環境默認自(zì)動隐藏index.php入口。
如(rú)果發現沒隐藏,可(kě)以檢查根目錄.htaccess是否含有以下代碼段:
<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>

如(rú)果存在,繼續查看(kàn)apache是否開啓了URL重寫模塊 rewrite_module , 然後重啓服務就(jiù)行了。