【问题标题】:Codigniter htaccess error 404 at production生产中的 Codeigniter htaccess 错误 404
【发布时间】:2016-10-19 21:37:38
【问题描述】:

我对服务器技术非常陌生。我知道这个问题问了太多次,但我真的没有让它运行。 它与
domain.com/2.0/index.php/test
一起运行,但是当你删除 index.php 时它会抛出

在此服务器上找不到请求的 URL /2.0/test。 Apache/2.2.15 (CentOS) 服务器在 domain.com 端口 443

我的项目结构
-
Public_html
--2.0(这是我的项目文件夹,可以在其中找到 ci。它有 sys、app、.htaccess)
--.htaccess

我的域
https://domain.com/2.0/

关于问题
我有两个 htaccess 一个在根目录上面提到的一个在 2.0 文件夹内
奇怪的是,我在 htaccess 文件中写的任何东西都没有任何影响

public_html/.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

public_html/2.0/.htaccess

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

我的 httpd.conf

<VirtualHost *:443>
    ServerAdmin info@domain.com
    DocumentRoot /home/natural/public_html
    ServerName api01.domain.net
    ErrorLog /var/log/httpd/error_log
    CustomLog /var/log/access_log common

    SSLEngine on
    SSLCertificateFile /home/natural/api01.domain.net.crt
    SSLCertificateKeyFile /home/natural/api01.domoin.key

    <Directory />
    Options Indexes FollowSymLinks
        Allow from all
        AllowOverride None
    </Directory>
</VirtualHost>

我搜索了很多,并通过堆栈溢出跟踪所有答案,但没有运气。

【问题讨论】:

  • 请更新问题以包含这些 .htaccess 文件的内容。答案可能是在根目录中添加重写条件以排除 2.0 文件夹下的所有内容。甚至将两个文件合并为一个。
  • 我更新了添加我的两个 htaccess 的问题
  • 添加文件夹结构的图片
  • @AbdulManan 你的项目是 2.0 吗?添加清晰的图像与应用程序文件夹和所有

标签: php apache .htaccess codeigniter mod-rewrite


【解决方案1】:

httpd.conf 中的指令“AllowOverride None”将禁用对指定目录(在本例中为 /)内的 .htaccess 文件的解析——您能否确认您的任何一个 .htaccess 文件实际上正在被解析?

如果没有,是否将 httpd.conf 文件中的 Directory 小节修改为:

<Directory />
Options Indexes FollowSymLinks
Allow from all
AllowOverride All
</Directory>

解决问题?

欲了解更多信息:http://httpd.apache.org/docs/2.4/mod/core.html#allowoverride

【讨论】:

  • 感谢精彩重播,我将 none 更改为 ALL 但没有 Luck
【解决方案2】:

我假设 2.0 是该站点的新版本。看起来/2.0/.htaccess 的写法好像它希望在根文件夹中一样。尝试在引擎启动后添加RewriteBase /2.0/。您可以稍后在将根文件夹的内容替换为 2.0 的内容时将其删除。

主要问题是您的# Handle Front Controller... 规则。它会在任何虚拟 URL 到达 2.0 文件夹之前捕获它们。尝试将其更改为:

RewriteRule ^(?!2\.0(?:/|$)) index.php [L]

这将从当前站点的虚拟 URL 中排除 2.0 文件夹。

按照其他答案的建议,您仍然需要AllowOverride all,并且目录应该与您的DocumentRoot 相同,而不是/

【讨论】:

  • 第一件事是 2.0 不是新版本它的其他东西 root 将持有网站 2.0 将持有 api
  • 你的意思是改成这样# Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(?!2\.0(?:/|$)) index.php [L]
  • 是的,我的意思是改变那一行,而不是删除其他行。
【解决方案3】:

将此代码添加到 root->.htaccess 文件中

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

【讨论】:

    猜你喜欢
    • 2013-05-13
    • 1970-01-01
    • 2013-07-28
    • 2014-01-04
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 2020-06-05
    • 2019-04-15
    相关资源
    最近更新 更多