【问题标题】:Codeigniter .htaccess代码点火器 .htaccess
【发布时间】:2011-07-28 08:01:53
【问题描述】:

对不起,我的英语不好......

我有最基本的 CodeIgniter 设置,但无法使其工作......如果我访问 url http://domain.com/index.php?controllerX/method 工作正常。

现在我希望能够访问 http://domain.com/method

我在 routes.php "controllerX" 上配置为默认控制器并尝试使用以下 .htaccess:

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

我尝试了多个 .htaccess 并且每次服务器只返回 403 错误。即使我的 .htaccess 仅包含第一行“RewriteEngine on”,它也会显示 403 错误。我尝试将每个文件夹设置为 chmod 777 或 755 进行测试,但没有任何改变。

有没有办法查看是什么资源导致了 403 错误?还是我在别处犯了错误?

好的,我在某个地方读到我的 htaccess 上需要“Options +FollowSymLink”...服务器显示 500 个错误:(

编辑 好的,现在它可以工作了,使用以下 htaccess:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

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

【问题讨论】:

  • 该选项称为+FollowSymLinks(末尾带有字母's')。
  • 你应该省略最后的重写条件(最后一行的旁边),它之前的 2 不再需要它。为了安全起见,您应该使用 SymLinksIfOwnerMatch 而不是 FollowSymLinks,它更安全。你的 [L] 也可以更好地与 [L,QSA] 一起使用,不过我的 2 美分

标签: .htaccess codeigniter-url


【解决方案1】:

将您的 .htaccess 文件更改为:

除了我们在 .htaccess 文件中所做的更改之外,我们还必须验证/更改以下设置:

Apache 读取位于 /var/www/html 目录下的 .htaccess 文件。 您可以通过编辑 httpd.conf 文件来做到这一点:

sudo nano /etc/httpd/conf/httpd.conf

找到该部分并将 AllowOverride None 更改为

AllowOverride All

 <Directory /var/www/html>
    AllowOverride All
 </Directory>
Save and exit.

现在重新启动 Apache 以使更改生效:

sudo systemctl 重启 httpd

这对我有用

【讨论】:

    【解决方案2】:

    我想你的问题也得到了回答here

    RewriteEngine On
    RewriteBase /
    
    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]
    
    # Enforce www
    # If you have subdomains, you can add them to 
    # the list using the "|" (OR) regex operator
    RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
    RewriteRule ^(.*)$ http://www.plugb.com/$1 [L,R=301]
    
    
    RewriteBase /    
    RewriteCond %{HTTP_HOST} !=""
    RewriteRule ^index.php(/.*)?$ http://%{HTTP_HOST}$1 [R=301]
    # 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
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多