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

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

问题描述

可以让Apache htaccess重写在命中django之前生效吗?

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

我想要指定 RewriteRules 在htaccess文件中优先于django,如果没有匹配,那么它将被调度到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 vhost看起来像这样:

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时需要查询,除了使用Alias指令映射的静态目录。

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

您需要做的是使用AddHandler方法来安装WSGI应用程序,并使用关联的重写规则以使其显示在网站的根目录,如下所述:

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://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive

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

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