如何从codeigniter中的url中删除index.php文件?

时间:2014-09-10 13:08:49

标签: php codeigniter

我正在尝试从我的网址中删除index.php,但我很困惑我在.htaccess文件中使用了哪些代码以及我必须对codeigniter中的相关文件进行哪些更改。

3 个答案:

答案 0 :(得分:0)

只需使用此.htaccess

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

取自here

答案 1 :(得分:0)

将此行添加到您的htaccess文件中:

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

答案 2 :(得分: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>