Django和重写的.htaccess /重定向,这可能吗? [英] Django AND .htaccess rewrites/redirects, is this possible?

查看:137
本文介绍了Django和重写的.htaccess /重定向,这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能让Apache的htaccess重写生效它​​击中的Django过吗?

Is it possible to have Apache htaccess rewrites take effect before it hits django?

我希望能够在需要precedence在Django的一个htaccess文件来指定的RewriteRules ,如果没有那么匹配它被分派到的mod_wsgi / Django的。

I want to be able to specify RewriteRules in an htaccess file that take precedence over django, and if nothing matches then it gets dispatched to mod_wsgi/django.

我们正在使用的Apache2与mod_wsgi的和Apache虚拟主机是这样的:

We're using apache2 with mod_wsgi and the apache vhost looks like this:

<VirtualHost *:80>

    DocumentRoot /usr/local/www/site/static

    Alias /css/ /usr/local/www/site/static/css/
    Alias /js/ /usr/local/www/site/static/js/
    Alias /img/ /usr/local/www/site/static/img/
    Alias /flash/ /usr/local/www/site/static/flash/

    <Directory /usr/local/www/site/static>
      AllowOverride All
      Order allow,deny
      Allow from all
    </Directory>

    WSGIDaemonProcess mallorca-site threads=15
    WSGIScriptAlias / /usr/local/www/site/config/dev/dev.wsgi

</VirtualHost>

感谢

推荐答案

首先你缺少WSGIProcessGroup指令。如果没有您的应用程序不会在守护进程模式下运行,你有定义WSGIDaemonProcess指令后可能的期望。

First off you are missing WSGIProcessGroup directive. Without that your application isn't going to be running in daemon mode as you possibly expect after having defined WSGIDaemonProcess directive.

其次,.htaccess文件甚至不打算使用,除了你的别名指令映射静态目录WSGIScriptAlias​​时查阅。

Secondly, a .htaccess file isn't even going to be consulted when using WSGIScriptAlias except for the static directories you mapped with Alias directives.

您需要做的是安装WSGI应用程序,关联重写规则得到它出现在网站的根目录,文件使用的AddHandler方法:

What you need to do is use AddHandler method for mounting WSGI application, with associated rewrite rules to get it to appear at root of site, as documented in:

http://$c$c.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive

这篇关于Django和重写的.htaccess /重定向,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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