如何使用.htaccess创建回退URL并将其与其他规则集成

时间:2011-09-27 14:10:32

标签: .htaccess

我有这样的目录结构......

.../htdocs/domain/example/    <==>  http://example.com/home/
.../htdocs/domain/example1/   <==>  http://example1.com/home/
.../htdocs/domain/example2/   <==>  http://example2.com/home/

我还有一个默认文件区......

.../htdocs/domain/default

我想请求......

http://example.com/home/logo.jpg   ==>  .../htdocs/domain/example/logo.jpg

 BUT if the file doesn't exist it should return

                                   ==>  .../htdocs/domain/default/logo.jpg

1 个答案:

答案 0 :(得分:0)

回答我自己的问题......

我在/ htdocs / domain /

中添加了这个.htaccess文件
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z]+)/(.*)$ /default/$2 [L]

我基本上说如果遇到未找到的文件,请尝试使用/ default

我发现如果我将默认内容放在/ htdocs / domain中我创建了一个递归问题,所以我只将它们放在/ htdocs / default