Apache vhost与CI .htaccess冲突

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

我正在通过qazxsw poi vhost文件中的以下代码将我的网站的子文件夹重写为子域:

Apache

所以RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. example.com RewriteCond %{HTTP_HOST} ^(www\.)?(([^\.]+)\.){1}example.com$ RewriteCond /var/www/example.com/web/crm/build/%3 -d RewriteRule ^/(.*) /crm/build/%3/$1 https://example.com/web/crm/ = https://folder.example.com

我也使用folder隐藏/index.php/在.htaccess网址

codeigniter

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

example.com/web/crm/folder我得到505内部错误,一旦我删除.htaccess中的行或只是通过folder.example.com/index.php/简单访问网站就可以了(日志中没有显示任何内容)

我想修复子域的重写冲突

php apache .htaccess codeigniter mod-rewrite
2个回答
0
投票

好的,两个建议:

  1. 很高兴知道导致HTTP 505的特定服务器端错误。 请将服务器日志中的确切消息复制/通过您的帖子。
  2. 确切地知道如何解释重写规则也是很好的。 请启用日志记录如下:

folder.example.com

How to debug Apache mod_rewrite

mod_rewrite提供了在trace1到trace8日志levels的进行的detailed日志记录。可以使用LogLevel指令专门为mod_rewrite设置日志级别:最多级别调试,不记录任何操作,而trace8表示几乎所有操作都被记录。

Apache Module
  mod_rewrite

George Samarguliani添加了此评论,解释了HTTP 505错误:

在vhost文件中添加重写日志规则后,apache无法启动httpd.service的Job失败,因为控制进程退出并显示错误代码。有关详细信息,请参阅“systemctl status httpd.service”和“journalctl -xe”。

我将上面的vhost片段复制/粘贴到第一个方便的Apache配置验证器LogLevel alert rewrite:trace6 中,并得到了:

https://htaccess.madewithlove.be/

所以现在至少我们知道是什么导致了服务器端错误:Apache vhost配置。

新建议:

  1. 至于“index.php”,我甚至认为你不需要或想要重写规则。 只需配置“DirectoryIndex”,如下所示: htaccess.MadeWithLove validator
  2. 至于URL的其余部分(例如``<Directory /myapp> DirectoryIndex index.php </Directory> `),请在您希望重定向实际工作的示例之前/之后更新您的帖子。
  3. 使用.htaccess / mod_rewrite规则有很多很好的“howtos”,有很好的例子。例如: qazxsw poi qazxsw poi http://example.com/web/crm/build/

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