Redirect subfolder request to Passenger

前提是你 提交于 2021-01-28 10:51:01

问题


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 RewriteRules 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!