我们通过一个下载链接分发不同版本的软件产品。传递是基于referer与默认值一起进行的,该默认值运行良好。此外,如果使用了错误的文件名,则应该将用户重定向到404-page。
目前,.htaccess-file看起来如下:
# stop directory listing
Options -Indexes
# turn rewrite engine on
RewriteEngine On
# force 404 if file name is missing or wrong
RewriteCond %{REQUEST_URI} !^(download_mac\.zip|download_pc\.zip)$
RewriteRule (.*) 404/index.html [L]
# an example based on the referer
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)*domain-a\.com [OR]
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)*domain-b\.com
RewriteRule ^(download_mac\.zip|download_pc\.zip)$ domain_ab/$1 [L]
# last rule if no referer matches
RewriteRule ^(download_mac\.zip|download_pc\.zip)$ default/$1 [L]因此,我对这个文件有一个问题和一个额外的问题:
RewriteCond %{REQUEST_URI} !^download_mac\.zip$这样的单一语句,但没有任何效果。我怎么才能解决这个问题?RewriteRule ^(.*)$ default/$1 [L]这样的东西,但是它给了我一个困难的时间和一个500 Internal Server Error。发布于 2013-04-22 16:07:59
通过使用这样的Env变量,可以避免重复文件名:
RewriteRule ^(download_mac\.zip|download_pc\.zip)$ - [E=ALLOWED:$1,NC]
RewriteCond %{ENV:ALLOWED} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /404/index.html [L]
RewriteCond %{ENV:ALLOWED} !^$
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)*domain-a\.com [OR]
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)*domain-b\.com
RewriteRule ^ /domain_ab/%{ENV:ALLOWED} [L]
RewriteCond %{ENV:ALLOWED} !^$
RewriteRule ^ /default/%{ENV:ALLOWED} [L]发布于 2013-04-22 16:33:37
你可以把重写规则移到最后。其他规则处理有效案例,如果它们都不匹配,则应用最后一条规则。
# an example based on the referer
RewriteCond %{HTTP_REFERER} ^http://([^.]+\.)*domain-[ab]\.com
RewriteRule ^download_(mac|pc)\.zip$ domain_ab/$0 [L]
# last rule if no referer matches
RewriteRule ^download_(mac|pc)\.zip$ default/$0 [L]
# force 404 if file name is missing or wrong
RewriteRule ^ 404/index.html [L]https://stackoverflow.com/questions/16150647
复制相似问题