【问题标题】:CodeIgniter htaccess 403CodeIgniter htaccess 403
【发布时间】:2023-03-29 16:22:02
【问题描述】:

我正在使用 CodeIgniter。我想从 url 中删除 index.php 部分。 我正在使用 CentOS。

我的 Apache 配置是:

<Directory "/var/www/html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>

我的文件位于: /var/www/html/project/site/ 然后网址是: example.com/project/site/

我的 htaccess 是:

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

来自官方 wiki。

我创建了一个带有 Site 类的 Site.php 控制器。 如果我转到 example.com/project/site/site,它会加载页面,但是由于 403 权限被拒绝错误,CSS 和 img 文件(位于 views/template/ 中)不会加载。

但是,如果我将 AllowOverride All 更改为 AllowOverride None 然后我会转到: example.com/project/site/index.php/site

它可以工作,所以文件的权限是好的。

顺便说一下,这是我的 config.php 文件:

$config['base_url'] = 'http://ipserver/project/site/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

解决方案

在配置 httpd 文件中添加 Satisfy Any 似乎可行。

【问题讨论】:

  • 您是如何引用您的资产的?您的资产的路径是什么?
  • 在视图中我有一个模板文件夹,包含 css、js 和其他子文件夹。我也有页面,其中有页面的主要 html。在这个页面中,我把这个: /images/bg/1.jpg 来自这个: $data['base_url'] = base_url('/application/views/template/');当然,这是控制器。

标签: php apache .htaccess codeigniter


【解决方案1】:

按照以下步骤操作:

  1. 像这样更改配置文件:

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

  2. 使用以下 .htaccess:

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

注意:.htaccess 因服务器而异。我的一些服务器(例如:Godaddy)需要使用以下 .htaccess:

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

来源链接:https://www.linkedin.com/groups/109912/109912-5948862618142785540

【讨论】:

猜你喜欢
  • 2018-08-30
  • 1970-01-01
  • 2020-12-12
  • 1970-01-01
  • 2012-05-16
  • 1970-01-01
  • 2012-04-21
  • 2012-07-04
  • 1970-01-01
相关资源
最近更新 更多