简体   繁体   English

目录索引页位于htaccess之前

[英]Directory index page precedes htaccess

What I want is that only if my root domain is accessed meaning URI is empty, it gets rewritten without redirect, otherwise rewrite to index.php if not accessing file or folder. 我想要的是,仅当访问我的根域(即URI为空)时,它才会被重写而不进行重定向;否则,如果不访问文件或文件夹,则被重写为index.php。 My .htaccess looks like this: 我的.htaccess看起来像这样:

RewriteEngine On
RewriteBase /
RewriteRule ^/?$ /mypages/landing_page.html [QSA,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

It works as expected on some servers but on another it works only if there is no index.php file in folder. 它可以在某些服务器上按预期方式工作,但在另一些服务器上,仅当文件夹中没有index.php文件时,它才能工作。 Something like directory indexing preceding htaccess rules? 类似于htaccess规则之前的目录索引? If I delete the index.php or rename it to index2.php and change my htaccess rules accordingly rewrite works as expected. 如果删除index.php或将其重命名为index2.php并相应地更改htaccess规则,则重写将按预期进行。

Any ideas what might be causing the server to behave like that? 有什么想法可能导致服务器出现这种情况吗?

There was a bug introduced in Apache 2.4.2 ( #53929 ) that has the same symptom you're describing: Apache 2.4.2( #53929 )中引入了一个与您描述的症状相同的错误:

"The issue is caused by the DirectoryIndex directive. mod_dir is not respecting the result of the rewrite execution. If DirectoryIndex is set to disabled, it starts working correctly." “问题是由DirectoryIndex指令引起的。mod_dir不考虑重写执行的结果。如果DirectoryIndex设置为Disabled,它将开始正常工作。”

The issue is fixed in Apache 2.4.9. 该问题已在Apache 2.4.9中修复。

If you have a mixed environment (ie pre and post Apache 2.4.2 versions), this could also explain why your Rewrite is working correctly on some servers, but not others. 如果您有混合环境(即Apache 2.4.2之前和之后的版本),这也可以解释为什么Rewrite在某些服务器上可以正常工作,而在其他服务器上却不能正常工作。

If upgrading is not an option, you can also workaround the issue using a conditional SetHandler (based on an env var set in your RewriteRule). 如果不能进行升级,则还可以使用条件SetHandler(基于RewriteRule中的env var)解决此问题。 This will disable DirectoryIndex for just those requests. 这将仅针对那些请求禁用DirectoryIndex。

The bug itself (and workaround example) is documented in the following link: 错误本身(和解决方法示例)在以下链接中记录:

https://bz.apache.org/bugzilla/show_bug.cgi?id=53929 https://bz.apache.org/bugzilla/show_bug.cgi?id=53929

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM