问题
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.
File structure:
- .htaccess
- subfolder/
- .htaccess
- some cms files
Content of root .htaccess
:
RewriteEngine on
... RewriteConds and RewriteRules generated by php cms
Content of subfolder/.htaccess
:
PassengerAppRoot "/home/username/djangoapplication"
PassengerPython "/home/username/virtualenv/webapp/2.7/bin/python2.7"
The problem is about root .htaccess
. When root .htaccess
is empty (constails only RewriteEngine on
) requests like mysite.com/subfolder/...
are handled by subfolder/.htaccess
and Django application loads. But when root .htaccess
contains lines generated by php cms all requests like mysite.com/subfolder/...
leads to the 404 error page from cms.
So I want to filter requests like mysite.com/subfolder/...
to subfolder/.htaccess
before RewriteRule
s from cms will replace it with 404 error page, but I can't figure it out how to do it.
回答1:
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
.
For example:
RewriteEngine On
PassengerAppRoot "/home/username/djangoapplication"
PassengerPython "/home/username/virtualenv/webapp/2.7/bin/python2.7"
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.
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]
This stops any further processing in the root .htaccess
file when the URL starts with /subfolder
.
来源:https://stackoverflow.com/questions/53044204/redirect-subfolder-request-to-passenger