Redhat:.htaccess 不工作

问题描述 投票:0回答:2

在 codeignitor .htaccess 无法在 Redhat 服务器上工作时,相同的 .htaccess 在本地服务器(即 xampp)上完美工作 还将 'AllowOverride None' 更改为 'AllowOverride All' 。请仅针对“redhat”给出答案。

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

phpinfo() 显示 Apache Configuration

php .htaccess codeigniter redhat
2个回答
0
投票

重写模块似乎是从您的屏幕截图中加载的。 您还可以通过添加此节从 VirtualHost 中启用 .htaccess:

  #Enable readin .htaccess
  <Directory "/var/www/html/mysite">
    AllowOverride All
  </Directory>

0
投票

如果您的 .htaccess 文件无法在 Red Hat 服务器上运行,您可以检查和调整一些内容。以下是排除和解决问题的一些步骤:

验证mod_rewrite模块:

确保您的 Apache 服务器上启用了 mod_rewrite 模块。您可以通过运行以下命令来完成此操作:

sudo apachectl -M | grep rewrite

如果该模块未列出,您可能需要启用它。在基于 Red Hat 的系统上,您可以使用:

sudo a2enmod rewrite

启用模块后,重新启动Apache:

sudo systemctl restart httpd

检查AllowOverride设置:

正如您所提到的,您已经更改了AllowOverride指令。确保在正确的配置文件中进行更改。在 Red Hat 系统上,Apache 配置通常位于 /etc/httpd/conf/httpd.conf 文件中。

打开Apache配置文件:

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

找到与您的 Web 目录对应的部分,并确保它具有以下或类似的行:

阿帕奇:

<Directory "/var/www/html">
   AllowOverride All
</Directory>

更改后,重新启动 Apache:

sudo systemctl restart httpd

检查 .htaccess 文件位置: 确保您的 .htaccess 文件位于 CodeIgniter 应用程序的根目录中。

验证.htaccess中的RewriteBase: 在 .htaccess 文件中,您可以尝试添加或修改 RewriteBase 指令。例如:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /your-subdirectory-if-any/
   RewriteCond $1 !^(index\.php|resources|robots\.txt)
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

调整 RewriteBase 以匹配应用程序的子目录结构。

检查 Apache 错误日志:

检查 Apache 错误日志中是否有与 .htaccess 文件相关的任何消息。错误日志位置可能有所不同,但通常位于 /var/log/httpd/error_log 中。查找可能表明问题根源的任何错误或警告。

sudo tail -f /var/log/httpd/error_log

进行这些调整后,您的 .htaccess 文件应该在 Red Hat 服务器上按预期工作。如果您遇到更多问题,查看 Apache 错误日志可以提供对问题的更多见解。

© www.soinside.com 2019 - 2024. All rights reserved.