4

我在重定向页面时是 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>
4

2 回答 2

2

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

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

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

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

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

    sudo a2dismod rewrite //禁用重写模式

    sudo a2enmod rewrite //启用重写模式

    sudo service apache2 restart //重启你的apache

这就是你需要做的所有事情。一切顺利。

于 2014-09-29T13:23:38.133 回答
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]
于 2014-09-26T10:22:40.513 回答