【问题标题】:code igniter can't remove index.php from URL代码点火器无法从 URL 中删除 index.php
【发布时间】:2016-03-15 22:55:10
【问题描述】:

我的 codeigniter 库位于一个名为“codeigniter”(非常原始)的文件夹下,所以我在这个加载良好的地址访问它,http://mysite.co.uk/codeigniter/index.php/pages/view/about

但是,如果地址中没有“index.php”,我无法使用以下地址http://mysite.co.uk/codeigniter/pages/view/about URL 访问我的“关于”页面,它一直在访问我的默认控制器而不是我的页面控制器。

我更新了以下内容:

config.php

$config['base_url'] = 'http://mysite';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

.htaccess

RewriteEngine on
RewriteBase /codeigniter/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

任何帮助都会很棒!

【问题讨论】:

  • 使$config['base_url'] = 'http://mysite'; 成为$config['base_url'] = 'http://mysite/'; - 注意斜线结尾。由docs提出。其次,尝试使用RewriteRule ^(.*)$ index.php?/$1 [L,QSA] - 注意问号(某些服务器需要修复)。最后但并非最不重要的一点是,重定向可能与APPPATH . 'routes.php' 有关,也许?
  • 感谢您的回复。我已经尝试了前 2 个建议,但仍然没有运气。 APPPATH 是什么意思?应该做出什么改变?
  • APPPATH 是您的/codeignter/application/ 目录的CI 常量,所以我弄错了,我的意思是APPPATH . 'config/routes.php' 文件。只是在问自己是否会出现你所描述的那样的结果。
  • 我必须访问 .htaccess 文件,一个与“系统”目录处于同一级别,另一个位于“应用程序”目录中。我需要更新哪一个?
  • 这些都不是。这些文件用于拒绝访问各个目录。通常,您应该只更改与index.php 文件相邻(与同一级别)的一个文件。

标签: php .htaccess codeigniter


【解决方案1】:

确保将“AllowOverride All”放置在您的 Apache 配置文件中,以便 .htaccess 起作用。

【讨论】:

  • 在哪里可以找到我的 Apache 配置文件?我对 PHP 很陌生,我通常是 Python 开发人员
  • 它位于Apache安装目录下的conf目录下。您应该能够看到 httpd.conf。那是Apache的主要配置文件。寻找 AllowOverride 然后重启 Apache 服务。
【解决方案2】:

你可以在你的 .htaccess 中使用它

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

【讨论】:

    【解决方案3】:

    您可以在 .htaccess 文件中使用它

    Options -Indexes 
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond $1 !^(index\.php|resources|robots\.txt)
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
            #RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
            #RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] 
            #RewriteRule \.(jpe?g|gif|bmp|png)$ - [F]
    </IfModule>  
    #Gzip
    <ifmodule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
    </ifmodule>
    <IfModule mod_headers.c>
    Header add Cache-Control:  "no-store, no-cache, must-revalidate"
    Header unset Pragma
    FileETag None
    Header unset ETag
    </IfModule>
    #End Gzip
    # BEGIN Expire headers  
    <ifModule mod_expires.c>  
        ExpiresActive On  
        ExpiresDefault "access plus 5 seconds"  
        ExpiresByType image/x-icon "access plus 2592000 seconds"  
        ExpiresByType image/jpg "access plus 2592000 seconds"
        ExpiresByType image/jpeg "access plus 2592000 seconds"
        ExpiresByType image/png "access plus 2592000 seconds"  
        ExpiresByType image/gif "access plus 2592000 seconds"  
        ExpiresByType text/x-javascript "access 1 month"
        ExpiresByType text/html "access plus 600 seconds"  
        ExpiresByType text/css "access plus 604800 seconds"  
        ExpiresByType text/javascript "access plus 216000 seconds"  
        ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"  
        ExpiresByType application/pdf "access 1 month"
        ExpiresByType application/javascript "access plus 216000 seconds"  
        ExpiresByType application/x-javascript "access plus 216000 seconds"  
        ExpiresByType application/xhtml+xml "access plus 600 seconds"  
    </ifModule>
    

    【讨论】:

      猜你喜欢
      • 2013-02-27
      • 2014-01-15
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 2012-11-14
      • 2019-03-22
      • 2013-08-09
      相关资源
      最近更新 更多