“此处不允许使用RewriteEngine";由htaccess在父目录中引起 [英] "RewriteEngine not allowed here" caused by htaccess in parent directory

查看:88
本文介绍了“此处不允许使用RewriteEngine";由htaccess在父目录中引起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在使用OSX Server(Yosemite)来托管一堆PHP应用程序,其中一些在子站点的网站文档根目录下具有一个子目录.自更新到OSX Server的Yosemite版本以来,这些子域一直抛出500错误,错误日志引用了RewriteEngine not allowed here.

Currently I am using OSX Server (Yosemite) to host a bunch of PHP applications, some of which have a sub-directory under the websites document root for subdomains. Since updating to the Yosemite version of OSX Server, these subdomains have been throwing a 500 error with the error log referring to RewriteEngine not allowed here.

调查中,我已经确认父站点站点和子站点站点均已配置AllowOverride All,并且.htaccess文件正在非子站点站点上工作.此外,我发现从父目录重命名或删除.htaccess文件会导致子域重新开始工作.

Investigating, I have confirmed that both the parent and subdomain sites have AllowOverride All configured, and .htaccess files are working on non-subdomain sites. Also, I have discovered that renaming or otherwise removing the .htaccess file from the parent directory causes the sub-domains to start working again.

/original_site_doc_root <- doc root for regular site
    .htaccess
    index.php
    ...
    subdomain/ <- configured as a seperate site in osx server as a subdomain
        .htaccess
        index.php
        ...

我进行的所有谷歌搜索最终都是指确保已安装mod_rewrite并正确配置了AllowOverride.

Every bit of googling I do ends up referring to making sure mod_rewrite is installed and AllowOverride is configured properly.

我的问题是,如何让Apache停止在子域网站上引发500错误?

My question is, how can I get Apache to stop throwing a 500 error on the sub-domain sites?

修改

这是子域的.htaccess文件,该文件引起了我的悲伤(模糊的域,目录和页面保护了无辜的人)

Here is the .htaccess file for the sub-domain that is causing me grief (with domains, directories and pages fuzzed to protect the innocent)

RewriteEngine On
Options +FollowSymlinks -Indexes
RewriteCond %{HTTP_HOST} ^www\.m\.somesite\.com$ [NC]
RewriteRule ^(.*)$ http://m.somesite.com/$1 [L,R=301]
RewriteBase /

# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0

# enable PHP error logging
php_flag  log_errors on
php_value error_log  /some/fuzzed/dir

RewriteRule ^$ /index.php [L]
RewriteRule ^home$ /home.php [L]

RewriteRule ^some-page1$ /some-page1.php [L]

RewriteRule ^some-page2$ /some-page2.php [L]

RewriteRule ^some-page3/(.*)$ /some-page32.php [L]
RewriteRule ^some-page3(\/?)$ /some-page32.php [L]

RewriteRule ^some-page4/(.*)$ /some-page4.php [L]
RewriteRule ^some-page4(\/?)$ /some-page4.php [L]

RewriteRule ^some-page5/(.*)$ /some-page5.php [L]
RewriteRule ^some-page5(\/?)$ /some-page5.php [L]

RewriteRule ^some-page6/(.*)$ /some-page6.php [L]
RewriteRule ^some-page6(\/?)$ /some-page6.php [L]

父目录/非子域站点的.htaccess大致相似,唯一相关的真正区别是前2行:

The .htaccess for the parent directory/non-sub-domain-site is more or less similar, with the only real difference of relevance being the top 2 lines:

RewriteEngine On
Options +FollowSymlinks -Indexes -Multiviews

推荐答案

只是遇到了同样的问题(在最近更新Apache2之后)并找到了解决方案.

Just ran into this same problem (after recent update Apache2) and found a solution.

假设您的域为example.com,目录为/var/www/example/,并且您有一个名为api.example.com的子域,目录为/var/www/example/api/.

Assume your domain is example.com and the directory is /var/www/example/, and you had a subdomain called api.example.com with directory /var/www/example/api/.

尝试使用以下内容:

<VirtualHost *:80>
 ServerName api.example.com
 DocumentRoot /var/www/example/api

 <Directory /var/www/example/>
     AllowOverride FileInfo Options
 </Directory>

 <Directory /var/www/example/api/>
     Require all granted
     Options +FollowSymLinks +MultiViews +ExecCGI -Indexes
     AllowOverride all
     Order allow,deny
     Allow from all
 </Directory>

</VirtualHost>

这应该有效!

这篇关于“此处不允许使用RewriteEngine";由htaccess在父目录中引起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆