繁体   English   中英

删除codeigniter的index.php

[英]Remove index.php of codeigniter

是的,另外一个。 我已经尝试了一切我在搜索中找不到运气的东西。

在我的httpd.conf(运行centos和apache2)中:

<VirtualHost *:80>
ServerName www.domain.com
ServerAlias domain.com *.domain.com
DocumentRoot /var/www/html/domain.com
</VirtualHost>

在我的htaccess /var/www/html/domain.com中:

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

似乎没有什么工作。

我试过添加

RewriteBase /

我已经尝试将最后一行切换为:

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

您需要确保在虚拟主机中拥有:

    <Directory "/path...to directory">
        Order allow,deny
        Allow from all
        Allowoverride all
    </Directory>

    <IfModule mod_rewrite.c>
        RewriteEngine on
    </IfModule>

原始帖子(以及CI用户指南)中的规则可用于允许URL在没有/index.php/情况下工作,但不会从现有URL中删除/index.php/

你可以设置$config['index_page'] = ''; (去除index.php在CI配置),以除去index.php从CI-生成的URL。

如果原始规则不起作用,请尝试这些重写规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

两点建议:

1.)确保将.htaccess文件保存/编辑到项目文件夹的根目录中,而不是/ applications文件夹中的.htaccess。 这样,如果我的应用程序文件夹位于项目/应用程序,则不要编辑项目/应用程序/ .htaccess文件。 您需要将文件放在project / .htaccess中

2.)在.htaccess文件中使用以下内容:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM