在没有index.php的情况下,codeigniter重定向不起作用?

时间:2014-09-26 07:52:00

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

我是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文件     ServerName localhost

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

2 个答案:

答案 0 :(得分:2)

你应该做些什么来避免url中的index.php

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

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

  • 使用nano命令编辑httpd.conf文件并包含main thing keepoveroveride All

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

    sudo a2dismod rewrite //禁用重写模式

    sudo a2enmod rewrite //启用重写模式

    sudo service apache2 restart //重新启动你的apache

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

答案 1 :(得分:1)

将其粘贴到.htaccess文件中

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