【问题标题】:Can't remove index.php from codeigniter site URL?无法从 codeigniter 站点 URL 中删除 index.php?
【发布时间】:2012-11-14 06:40:33
【问题描述】:

我已阅读有关它的删除指南,他们告诉我将其添加到我的 htdocs 根目录中的 .htaccess 中:

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

但是我的网站目录是这样的:htdocs\mywebsite\

我尝试在 htdocs 和 mywebsite 中添加 htaccess 文件,但没有结果。 我也试过修改最后一行看起来像

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

在 htdocs 和 mywebsite 目录中。但我不知道什么是正确的 .htaccess 语法或它是如何工作的,所以我真的没想到它会起作用。

我还尝试在 codeigniter 目录树的其他任何地方修改 .htaccess 文件。

【问题讨论】:

    标签: php .htaccess codeigniter url indexing


    【解决方案1】:

    你见过这个吗? How to remove "index.php" in codeigniter's path

    您是否更改了配置文件中的 index_path 变量?那就是application/config/config.php,2.1.3版本的第29行

    【讨论】:

    • 我不知道我必须更改 index_path。我应该把它改成什么?
    • 将其设为空字符串:$config['index_path'] = '';就是这样,我想
    • 我认为您需要将 .htaccess 文件添加到 index.php 文件所在的任何位置,您这样做了吗?查看我发送的链接。
    • 是的,它在根目录和 mywebsites 目录中。我使用了链接中的改进代码。还是不行。
    【解决方案2】:

    确保你的虚拟主机条目中有这个:

        <Directory "/path...to directory">
            Order allow,deny
            Allow from all
            Allowoverride all
        </Directory>
    
        <IfModule mod_rewrite.c>
            RewriteEngine on
        </IfModule>
    

    您不需要修改任何 .htaccess 文件,除了根目录。如上所述,请确保您在 config.php 文件中进行了正确设置。

    【讨论】:

      【解决方案3】:

      根目录和网站目录中都需要有一个 htaccess 文件。它们都需要包含相同的内容,除了根目录中的文件需要更新索引的路径以包含您的网站目录。

      根目录:

      RewriteEngine on
      RewriteBase /
      # Hide the application and system directories by redirecting the request to index.php
      RewriteRule ^(application|system|\.svn) index.php/$1 [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ yourwebsite/index.php/$1 [QSA,L]
      

      网站目录:

      RewriteEngine on
      RewriteBase /
      # Hide the application and system directories by redirecting the request to index.php
      RewriteRule ^(application|system|\.svn) index.php/$1 [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
      

      【讨论】:

        猜你喜欢
        • 2018-03-30
        • 2013-08-09
        • 2012-12-27
        • 1970-01-01
        • 1970-01-01
        • 2023-03-25
        • 2015-05-26
        • 1970-01-01
        • 2012-07-19
        相关资源
        最近更新 更多