2014-09-10 37 views
-2

我想從我的url中刪除index.php,但我很困惑我在.htaccess文件中使用哪個代碼,以及我在codeigniter中的相關文件上做了哪些更改。如何從codeigniter中的URL中刪除index.php文件?

+0

可能重複的[在codeigniter 2.1.0中刪除index.php](http://stackoverflow.com/questions/9667226/remove-index-php-in-codeigniter-2-1-0) – Dan 2014-09-10 13:23:22

回答

0

兩者

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

只是這行添加到您的htaccess文件:

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule .* index.php/$0 [PT,L]  
</IfModule> 
0

如果您使用IIS,嘗試importing these rules您web.config文件:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
<system.webServer> 
    <rewrite> 
     <rules> 
      <rule name="Rule 1" stopProcessing="true"> 
       <match url="^(.*)$" ignoreCase="false" /> 
       <conditions logicalGrouping="MatchAll">* 
        <add input="{URL}" pattern="^system.*" ignoreCase="false" /> 
       </conditions> 
       <action type="Rewrite" url="index.php?/{R:1}" appendQueryString="false" /> 
      </rule> 
      <rule name="Rule 2" stopProcessing="true"> 
       <match url="^(.*)$" ignoreCase="false" /> 
       <conditions logicalGrouping="MatchAll"> 
        <add input="{URL}" pattern="^application.*" ignoreCase="false" /> 
       </conditions> 
       <action type="Rewrite" url="/index.php?/{R:1}" appendQueryString="false" /> 
      </rule> 
      <rule name="Rule 3" stopProcessing="true"> 
       <match url="^(.*)$" ignoreCase="false" /> 
       <conditions logicalGrouping="MatchAll"> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> 
       </conditions> 
       <action type="Rewrite" url="index.php?/{R:1}" appendQueryString="false" /> 
      </rule> 
     </rules> 
    </rewrite> 
</system.webServer>