【问题标题】:Removing a index.php from codeginiter url using htaccess not working on server使用 htaccess 从 codeginiter url 中删除 index.php 在服务器上不起作用
【发布时间】:2015-12-29 00:31:07
【问题描述】:

.ht 访问代码:

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

配置文件也有变化:

$config['index_page'] = ' ';

$config['uri_protocol'] = "REQUEST_URI";

mod_rewrite 也已启用。 虽然这段代码不起作用。

【问题讨论】:

  • 你在运行 wamp lamp 等什么 apache 服务器
  • apache 服务器正在运行...并且服务器在 CentOS 中。
  • 我正在使用 cassandra 数据库
  • 在 cent os 中,您对您的 httpd.conf 文件进行了小改动并重新启动。 .Htaccess 在您进行更改之前将无法工作。

标签: .htaccess codeigniter mod-rewrite


【解决方案1】:

当您要求 Apache 将 URI 发送到 QUERY_STRING 时,您不能使用 REQUEST_URI 协议。

所以要么更改您的.htaccess 或您的配置,以便它们匹配。我的建议是改.htaccess

RewriteRule ^ index.php [L]

【讨论】:

  • 那么使用您以前的.htaccess 代码然后将协议从REQUEST_URI 更改为QUERY_STRING 怎么样?
  • 另外,index_page 设置中有一个不必要的空间。将' ' 更改为''
  • 我已经尝试了协议的所有选项,但它不能工作......我不明白是什么问题
【解决方案2】:

您是否尝试过提供AUTO 而不是REQUEST_URI。即使我有类似的问题,但当我将其更改为 AUTO 并在我的情况下对 .htaccess 进行小的更改时得到了解决。

$config['index_page'] = '';

$config['uri_protocol'] = 'AUTO';

.htaccess-

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

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

如果不适用于您的情况,抱歉。

CodeIgniter htaccess and URL rewrite issues

【讨论】:

  • 注意:Codeigniter 3 没有 AUTO。
【解决方案3】:

我已经运行 CI 3 应用程序并且可以正常使用这个 .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

【讨论】:

    【解决方案4】:

    改变这个

    在'config.php`中

    $config['base_url'] = '';
    $config['index_page'] = ''
    $config['uri_protocol'] = 'AUTO';
    

    .htaccess

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L] 
    </IfModule>
    

    并且访问 URL 应该使用base_url() 函数。

    &lt;form action="&lt;?php echo base_url()?&gt;Controller_name/Method_name"

    注意:要使用base_url(),您必须在autoload.php上启用它

    $autoload['helper'] = array('url');
    

    【讨论】:

    • 在此服务器上找不到请求的 URL
    • 你把我的.htaccess 放了吗??
    • 我的服务器在 CentOS 中。服务器有问题吗?
    • @RubbySmith Read this
    猜你喜欢
    • 2014-02-10
    • 2016-05-09
    • 1970-01-01
    • 2021-10-02
    • 2015-01-20
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多