将子文件夹请求重定向到乘客 [英] Redirect subfolder request to Passenger
问题描述
我想将所有诸如 mysite.com/subfolder/...
之类的请求重定向到乘客上的Django应用程序,并将所有其他请求重定向到在某些php cms下运行的网站.
I want to redirect all requests like mysite.com/subfolder/...
to Django application over Passenger and all other requests to the website running under some php cms.
文件结构:
- .htaccess
- 子文件夹/
- .htaccess
根
.htaccess
的内容:RewriteEngine on ... RewriteConds and RewriteRules generated by php cms
子文件夹/.htaccess
的内容:PassengerAppRoot "/home/username/djangoapplication" PassengerPython "/home/username/virtualenv/webapp/2.7/bin/python2.7"
问题与根
.htaccess
有关.如果根.htaccess
为空(仅使用RewriteEngine on
),则mysite.com/subfolder/...
之类的请求将由处理subfolder/.htaccess
和Django应用程序加载.但是,当根.htaccess
包含php cms生成的行时,所有请求(例如mysite.com/subfolder/...
)都会导致来自cms的404错误页面.The problem is about root
.htaccess
. When root.htaccess
is empty (constails onlyRewriteEngine on
) requests likemysite.com/subfolder/...
are handled bysubfolder/.htaccess
and Django application loads. But when root.htaccess
contains lines generated by php cms all requests likemysite.com/subfolder/...
leads to the 404 error page from cms.所以我想在cms的
RewriteRule
之前将诸如mysite.com/subfolder/...
之类的请求过滤到subfolder/.htaccess
将其替换为404错误页面,但我不知道该怎么做.So I want to filter requests like
mysite.com/subfolder/...
tosubfolder/.htaccess
beforeRewriteRule
s from cms will replace it with 404 error page, but I can't figure it out how to do it.推荐答案
如果根
.htaccess
文件仅包含mod_rewrite指令,则可以完全覆盖根.htaccess
只需在/subfolder/.htaccess
中启用重写引擎即可.If the root
.htaccess
file only contains mod_rewrite directives then you can completely override the root.htaccess
file by simply enabling the rewrite engine in/subfolder/.htaccess
.例如:
RewriteEngine On PassengerAppRoot "/home/username/djangoapplication" PassengerPython "/home/username/virtualenv/webapp/2.7/bin/python2.7"
默认情况下,默认情况下不继承mod_rewrite指令 (与其他模块不同).但是,可能已在服务器配置中专门启用了mod_rewrite继承,所以这可能行不通.
By default, mod_rewrite directives are not inherited by default (unlike other modules). However, it is possible that mod_rewrite inheritance has been specifically enabled in your server config, so this may not work.
如果这不起作用,则需要在根
.htaccess
文件的顶部创建一个例外,以防止请求/subfolder/
覆盖.例如:If this doesn't work then you would need to create an exception at the top of the root
.htaccess
file, that prevents requests for the/subfolder/
being overridden. For example:RewriteRule ^subfolder - [L]
当URL以
/subfolder
开头时,这会停止在.htaccess
根文件中进行任何进一步的处理.This stops any further processing in the root
.htaccess
file when the URL starts with/subfolder
.这篇关于将子文件夹请求重定向到乘客的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!