开发者

How to create a fallback URL using .htaccess and integrate it with other rules

I have a directory structure like this...

.../htdocs/domain/example/    <==>  http://example.com/home/
.../htdocs/domain/example1/   <==>  http://example1.com/home/
.../htdocs/dom开发者_Go百科ain/example2/   <==>  http://example2.com/home/

And I also have a default file area...

.../htdocs/domain/default

I would like a request for...

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


Answering my own question...

I added this .htaccess file in /htdocs/domain/

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z]+)/(.*)$ /default/$2 [L]

I basically says if you encountewr a file that isn't found then try in /default

I found that I created a recursive issue if I placed the default stuff in /htdocs/domain so I just place those in /htdocs/default

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜