【问题标题】:In codeigniter redirecting is not working without index.php?在没有 index.php 的情况下,codeigniter 重定向不起作用?
【发布时间】:2014-11-21 04:09:40
【问题描述】:

在重定向页面时我是 codeigniter 的新手 index.php 默认情况下不会加载,所以我在 htaccess 文件中尝试了以下代码。我已经安装了 php 5.3.10、apache 服务器和 postgres 数据库。因此,如果除了更改 .htaccess 和 httpd.conf 之外还需要进行任何新配置,请告诉我。我已经看到以前针对同一问题提出的问题,并且我参考了这些问题中的所有内容,但我仍然无法解决这个问题。请让我知道需要做哪些额外的事情。

.htaccess 文件

 <IfModule mod_rewrite.c> RewriteEngine On #Checks to see if the user is attempting to access a valid file, #such as an image or css document, if this isn't true it sends the #request to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d #This last condition enables access to the images and css folders, and the robots.txt file RewriteCond $1 !^(index\.php|public|images|robots\.txt|css) RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
    RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^/(index\.php|assets/|humans\.txt) RewriteRule ^(.*)$ index.php/$1 [L]
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L] 

httpd.conf 文件 服务器名称 localhost

<Directory />
   Options FollowSymLinks
   AllowOverride All
   Order deny,allow
   Deny from all
</Directory>

【问题讨论】:

  • 是否启用了重写模块?
  • 确保$config['index_page'] = '';application/config/config.php
  • 检查文件权限 sudo chmod 777 -R projectDirectory/
  • @Pooshonk 先生,我已经引用了该链接,我已经尝试了这些代码,但它仍然无法正常工作。

标签: codeigniter codeigniter-2 codeigniter-url codeigniter-routing codeigniter-3


【解决方案1】:

为了避免在 url 中出现 index.php,您应该采取以下措施

  • 始终确保您拥有 .htaccess 文件。你已经有了。

  • 在 .htaccess 中包含 @charlie 上面建议的内容。

  • 使用 nano 命令编辑 httpd.conf 文件并包含主要内容 keep allowoveride All

  • 首先禁用重写模式并再次启用它,然后使用以下命令重新启动 apache2 服务器。

    sudo a2dismod rewrite //禁用重写模式

    sudo a2enmod rewrite //开启重写模式

    sudo service apache2 restart //重启你的apache

这就是你需要做的。一切顺利。

【讨论】:

    【解决方案2】:

    将此粘贴​​到您的 .htaccess 文件中

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

    【讨论】:

    • @Charle Sir,我试过这段代码,它不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 2019-11-23
    相关资源
    最近更新 更多