【问题标题】:how to remove index.php from url using .htaccess如何使用 .htaccess 从 url 中删除 index.php
【发布时间】:2014-07-14 10:25:19
【问题描述】:

我正在开发 yii 框架并尝试从 url (httpx://localhost:801/index.php/aImages) 中删除 index.php,它应该像这样 httpx://localhost:801/aImages 。所以下面给出的代码在我的 .htaccess 文件中。此代码在我的本地主机上运行,​​但在我的团队成员机器上运行。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

【问题讨论】:

标签: php apache .htaccess yii


【解决方案1】:

试试:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

在你的配置文件中,使用:

...
'urlFormat'=>'path',
'showScriptName'=>false,
...

【讨论】:

    【解决方案2】:
    RewriteEngine on
    
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # otherwise forward it to index.php
    RewriteRule . index.php
    

    参考:http://www.yiiframework.com/doc/guide/1.1/en/topics.url

    【讨论】:

      【解决方案3】:

      你需要创建.htaccess文件

      RewriteEngine On
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
      

      您可以查看here以获取更多参考。

      【讨论】:

      • 感谢 nana.chorage,您的回复非常有帮助,实际上 rewrite_module 不起作用,您提供的链接确实有帮助。
      【解决方案4】:

      试试这个规则

      RewriteRule ^index\.php/$ $1 [R=301,L]
      

      【讨论】:

        【解决方案5】:

        最后一行应该是

        RewriteRule (.*) index.php/$1 [L]
        

        【讨论】:

          【解决方案6】:

          转到 .htaccess 文件并添加以下行...

          重写引擎开启

          RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d

          重写规则。 index.php

          【讨论】:

            猜你喜欢
            • 2021-10-02
            • 2015-01-20
            • 2023-03-07
            • 1970-01-01
            • 2011-05-20
            • 2017-03-15
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多