【发布时间】:2015-04-21 20:38:16
【问题描述】:
我正在尝试将在一个域上发出的文件请求重定向到子域。请求的文件混合在一起:.doc、.docx、.pdf、.ppt 和 .pptx。
到目前为止,我一直未能成功编写规则来实现这一点:
RewriteCond %{HTTP_HOST} ^domain\.org\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.org\.uk$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^dir1\/subdir1\/subdir\/(.+\.(pdf|doc|docx|ppt|pptx)$ "http\:\/\/subdomain\.domain\.org\.uk\/newdir\/$1" [NC,R=302,L]
我在有和没有 HTTP_HOST 条件的情况下都试过了。
请有人指出正确的方向,为什么这不起作用?
谢谢。
编辑
.htaccess 示例
#The first rule
RewriteEngine On
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^domain\.org\.uk$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#The last (working) rule before the rule I'm trying to implement
RewriteCond %{HTTP_HOST} ^domain\.org\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.org\.uk$
RewriteRule ^apply\/?(.*)$ "http\:\/\/subdomain\.domain\.org\.uk\/$1" [R=301,L]
#The rule I'm trying to get working
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.org\.uk$ [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^dir1/subdir1/subdir/(.+\.(pdf|docx?|pptx?))$ http://subdomain.domain.org.uk/newdir/$1 [R=302,NC,L]
【问题讨论】:
-
提供商已告知我“.pdf 或 .doc 等静态文件将绕过 Apache,因为它们不是由 nginX 提供的。完成这项工作的唯一方法是启用直接推送域”。
标签: apache .htaccess mod-rewrite redirect