在已经运行的Drupal网站的子目录运行Django项目子目录、项目、网站、Drupal

由网友(你若是梦,我愿长眠)分享简介:此问题已被窃听我的最后一个星期左右,现在我在最后期限即将到来。我有一个网站,在Web根目录(servername.org)运行的Drupal媒体寺DV服务器上。我加入一个Django的网站,我想这是设在URL servername.org/myproject。我建项目(在不在根目录的目录)和它工作正常,当我与Djang...

此问题已被窃听我的最后一个星期左右,现在我在最后期限即将到来。我有一个网站,在Web根目录(servername.org)运行的Drupal媒体寺DV服务器上。我加入一个Django的网站,我想这是设在URL servername.org/myproject。我建项目(在不在根目录的目录)和它工作正常,当我与Django的开发服务器运行它,但我不能获得Apache配置为运行我的Django的网站。 我跟着这个教程的http://how.4cpus.com/installing-django-on-mt-media-temple-dv-35-server-with-mod_python/

做初始设置和配置vhost..conf的解释存在。但Drupal的生成.htaccess文件一直抓住我的网址,并返回404错误。

唯一的变通方法我到目前为止的是,如果我创建的根目录的子目录称为httpdocs资料/ MyProject的,然后转到这个URL servername.org/myproject它的工作原理。但是,一旦我试着去myproject的任何子文件夹(如服务器名/ MyProject的/登录)我再次获得404错误。

任何帮助吗?我知道它必须是一个简单的一两行的Apache配置的事情,但我不出去,我跑出来的想法。

下面是从vhost.conf文件中的一个片段:

 <位置/ MyProject的/>
  SetHandler的python程序
  PYTHONPATH['/var/www/vhosts/servename.org/']+sys.path
  PythonHandler django.core.handlers.modpython
  SETENV DJANGO_SETTINGS_MODULE myproject.settings
  PythonInter preTER的myproject
< /地点>
 
JavaWeb SSM SpringBoot学生信息管理系统 源码 可运行 精品毕设 主要功能 登陆 学生管理 班级管理 教师管理 课程 选课管理 考勤管理 请假管理 成绩管理

这里是根目录Drupal的.htaccess文件(注意rewirte规则,我把附近不会出现做任何事情年底):

 #
#阿帕奇/ PHP / Drupal的设置:
#

#从窥探保护的文件和目录。
< FilesMatch ".(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(.php)?|xtmpl|svn-base)$|^($c$c-style.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  订购允许,拒绝
< / FilesMatch>

#不要显示目录列表它映射到一个目录下的网址。
选项​​-Indexes

#在此目录中使用符号连接。
选项​​+的FollowSymLinks

#使Drupal的处理任何404错误。
的ErrorDocument 404的index.php

#为不存在的favicon.ico请求强制简单的错误消息。
<文件的favicon.ico>
  #下面有没有结束的报价,对于与Apache 1.3的兼容性。
  的ErrorDocument 404所请求的文件的favicon.ico没有被发现。
< /文件>

#设置默认的处理程序。
的DirectoryIndex index.php文件

#覆盖PHP的设置。更多网站/默认/ settings.php文件
#但下面不能在运行时更改。

#PHP 4,Apache的1。
< IfModule mod_php4.c被>
  php_value magic_quotes_gpc的0
  php_value了register_globals 0
  php_value session.auto_start 0
  php_value合格的mbstring.http_input
  php_value的mbstring.http_output通
  php_value中的mbstring.encoding_translation 0
< / IfModule>

#PHP 4,阿帕奇2。
< IfModule sapi_apache2.c>
  php_value magic_quotes_gpc的0
  php_value了register_globals 0
  php_value session.auto_start 0
  php_value合格的mbstring.http_input
  php_value的mbstring.http_output通
  php_value中的mbstring.encoding_translation 0
< / IfModule>

#PHP 5中,阿帕奇1和2。
< IfModule mod_php5.c>
  php_value magic_quotes_gpc的0
  php_value了register_globals 0
  php_value session.auto_start 0
  php_value合格的mbstring.http_input
  php_value的mbstring.http_output通
  php_value中的mbstring.encoding_translation 0
< / IfModule>

#要求mod_expires被激活。
< IfModule mod_expires.c>
  #开启到期。
  ExpiresActive在

  #缓存的访问后,所有文件2周(A)。
  ExpiresDefault A1209600

  < FilesMatch  .PHP $>
    #不要让PHP脚本被缓存,除非他们明确地发送缓存
    #头自己。否则,所有的脚本必须覆盖
    #头通过mod_expires设置,如果他们想要另一个缓存行为。这可能
    #如果早发生在引导过程中的错误而失败,并可能会导致
    #问题,如果一个非Drupal的PHP文件被安装在一个子目录中。
    ExpiresActive关闭
  < / FilesMatch>
< / IfModule>

#各个重写规则。
< IfModule mod_rewrite.c>
  RewriteEngine叙述上

  #如果您的网站既可以有和没有访问WWW。 preFIX,你
  #可以使用以下设置之一将用户重定向到您的preferred
  #URL,无论有或没有的WWW。 preFIX。只选择一个选项:
  #
  #重定向所有用户访问该网站的WWW。 preFIX,
  #(HTTP://example.com / ...将被重定向到http://www.example.com / ...)
  #调整和取消以下:
  #的RewriteCond%{HTTP_HOST} ^例如 .COM $ [NC]
  #重写规则^(。*)$ http://www.example.com/$1 [L,R = 301]
  #
  #重定向所有用户访问该网站没有WWW。 preFIX,
  #(HTTP://www.example.com / ...将被重定向到http://example.com / ...)
  #取消和调整如下:
  #的RewriteCond%{HTTP_HOST} ^ WWW  .EXAMPLE  .COM $ [NC]
  #重写规则^(。*)$ http://example.com/$1 [L,R = 301]

  #修改的RewriteBase如果你是在一个子目录或在使用Drupal的
  #VirtualDocumentRoot和重写规则都不能正常工作。
  #例如,如果你的网站是在http://example.com/drupal取消注释和
  #修改下面一行:
  #的RewriteBase / Drupal的
  #
  #如果你的网站是在一个VirtualDocumentRoot在http://example.com/运行,
  #取消以下行:
  #的RewriteBase /

  #添加人威尔黑2010年10月7号
  的RewriteCond%{REQUEST_URI}/ MyProject的/
  重写规则(。*)$ 1 [L]

  #重写形式的网址X的形式的index.php?Q = X'。
  的RewriteCond%{} REQUEST_FILENAME!-f
  的RewriteCond%{} REQUEST_FILENAME!-d
  的RewriteCond%{REQUEST_URI}!= /的favicon.ico
  重写规则^(。*)$的index.php?Q = $ 1 [L,QSA]
< / IfModule>

#$编号:的.htaccess,V 1.90.2.4 2009/12/07 12点00分40秒戈巴精通$


  [1]:http://how.4cpus.com/installing-django-on-mt-media-temple-dv-35-server-with-mod_python/
 

解决方案

该问题可能是Drupal的抓住URL的是形式域/路径1 /路径,并将其转换为域名?Q =路径1 /路径,因而是可能抓住的一切,试图去Django的,并把它变成一个Drupal电话。所以我的猜测是,你需要做的就是添加一个新的重写条件,Drupal的htaccess的告诉它忽略任何针对Django的子目录。我没有这样做过,但我猜你希望是这样的:

 的RewriteCond%{REQUEST_URI}!= / Django_subdirectory
 

这应该与所有的其他条件重写在该文件中。

This problem has been bugging me for the last week or so and now I am coming up on a deadline. I have a site on a Media Temple DV server that is running Drupal in the webroot (servername.org). I am adding a django site and I would like it to be located at the url servername.org/myproject. I have build the project (in a directory not in the webroot) and it is working fine when I run it with the django dev server but I cannot get apache configured to run my django site. I followed this tutorial http://how.4cpus.com/installing-django-on-mt-media-temple-dv-35-server-with-mod_python/

to do the initial setup and configured vhost..conf as explained there. But the Drupal generated .htaccess file keeps grabbing my url and returning a 404 error.

The only work around I have so far is that if I create a subdirectory in webroot called httpdocs/myproject and then goto the url servername.org/myproject it works. But as soon I try to go to any subfolder of myproject (e.g. servername/myproject/login) I get the 404 error again.

Any help here? I know it must be an easy one or two line apache configuration thing but I can't figure it out and I'm running out of ideas.

Here is a snippet from the vhost.conf file:

<Location "/myproject/">
  SetHandler python-program
  PythonPath "['/var/www/vhosts/servename.org/']+sys.path"
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE myproject.settings
  PythonInterpreter myproject
</Location>

And here is the Drupal .htaccess file in webroot (notice the rewirte rule I put in near the end that doesn't appear to do anything):

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch ".(engine|inc|info|install|module|profile|test|po|sh|.*sql|theme|tpl(.php)?|xtmpl|svn-base)$|^(code-style.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  Order allow,deny
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Force simple error message for requests for non-existent favicon.ico.
<Files favicon.ico>
  # There is no end quote below, for compatibility with Apache 1.3.
  ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1.
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch .php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} ^example.com$ [NC]
  # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
  # RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
  # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

  # Added by Wil Black Oct. 7, 2010
  RewriteCond %{REQUEST_URI} "/myproject/"
  RewriteRule (.*) $1 [L]

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

# $Id: .htaccess,v 1.90.2.4 2009/12/07 12:00:40 goba Exp $


  [1]: http://how.4cpus.com/installing-django-on-mt-media-temple-dv-35-server-with-mod_python/

解决方案

The problem is probably that drupal grabs URL's that are in the form domain/path1/path2 and converts them to domain?q=path1/path2, and thus is probably grabbing everything that is trying to get to Django, and turning it into a drupal call. So my guess is that what you need to do is add a new rewrite condition to drupal's htaccess telling it to ignore anything targeted at the Django subdirectory. I haven't done this before, but I would guess you want something like this:

  RewriteCond %{REQUEST_URI} !=/Django_subdirectory

This should go along with all of the other rewrite conditions in that file.

阅读全文

相关推荐

最新文章