OpenShift,Python 2.7和静态文件与htaccess

我正在尝试configurationapache来为site.com/img/bla.jpg URL提供静态文件。 Python墨盒+烧瓶。

我知道什么是wsg/static目录的预configuration别名,所以我们可以使用site.com/static/bla.jpg 。 但是我需要额外的静态目录。

项目结构:

 /wsgi .htaccess /img -> $OPENSHIFT_DATA_DIR/some/path (soft link) /static application 

在后端我绑定了mysite.com/img/<filename>来testingapache或后端是否处理文件 – 它返回“ok [filename]”string。

我已经尝试在htaccess中的以下configuration:

1site.com/img/1.jpg – >“ok 1.jpg”

 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f # with and without this condition RewriteRule ^img/(.+)$ /static/$1 [L] # RewriteRule ^img/(.+)$ /img/$1 [L] # RewriteRule ^/img/(.+)$ /img/$1 [L] # RewriteRule ^img/(.+)$ http://img.zgserver.com/python/i1_3d265689.png [L] 

据我了解正则expression式不匹配请求的URL和Apache只是传递的东西后端?

2site.com/img/1.jpg – >“ok 1.jpg”

 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule /img/1.jpg http://img.zgserver.com/python/i1_3d265689.png [L] 

3site.com/img/1.jpg – >打开google的i1_3d265689.png

 RewriteEngine On RewriteBase / RewriteRule /img/1.jpg http://img.zgserver.com/python/i1_3d265689.png [L] 

注意:没有RewriteCond。

那么如何使它工作?

再次我想要Apache服务mysite.com/img/<filename>作为wsg/img/<filename>

openshift有什么问题,或者我错过了什么?

看起来我想通了。 这个问题分两步解决:

  1. 所有的静态文件必须放在wsgi/static如果你想让Apache为你服务(而不是你的后端脚本)。 你不能配置apache使用另一个目录,因为你只能用.htaccess文件来操作,而不允许配置这样的东西。 所以我不能从wsgi/img$OPENSHIFT_DATA_DIR/img制作apache服务资产。 我必须创建符号链接到wsgi/static内的这些目录:

     /wsgi /static /img -> (symlink) $OPENSHIFT_DATA_DIR/img 

    现在我们可以通过site.com/static/img/1.jpg访问图片。

  2. 现在我们需要在wsgi/.htaccess中将site.com/static/img/1.jpg映射到site.com/img/1.jpg 。 就像是:

     RewriteRule ^img/(.+)$ /static/img/$1 [L] or RewriteRule ^/img/(.+)$ /static/img/$1 [L] 

    由于正则表达式的作用力从URL路径( ^ )开始搜索,所以它不起作用。 问题是什么OpenShift的Apache URL路径是<wsgi app name>/%{REQUEST_URI} (至少对于RewriteRule )。 application/img/1.jpg在我的情况下。 因此, ^img/(.+)$ ^/img/(.+)$都不会匹配URL路径。 我不是一个Apache专家,但也许这个模板配置链接可能会帮助别人找出URL路径问题。 所以解决方法是删除^

     RewriteRule /img/(.+)$ /static/img/$1 [L] 

    现在我们可以使用site.com/img/1.imgsite.com/randomstuff/img/1.img也可以使用。 所以我使用RewriteCond来过滤这样的网址。

这是我的最终解决方案:

 RewriteEngine On RewriteCond %{REQUEST_URI} ^/img/ RewriteRule /img/(.+)$ /static/img/$1 [L]