如果文件不存在,则将Mod重写重定向到另一个域 [英] Mod rewrite redirection to another domain if file not exist

查看:76
本文介绍了如果文件不存在,则将Mod重写重定向到另一个域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果文件不存在,我需要将对文件的请求重定向到另一个域.例如:

I need to redirect a request to a file to another domain if the file not exists. For example:

http://www.mydomain.com/js/foo.js 

重定向到(如果不存在)

redirects to (if not exists)

http://www.myanotherdomain.com/js/foo.js

我做什么:

我在htaccess的末尾写了下一行,但是它们重定向了ALL!

What I do:

I wrote the next lines at the end the htaccess, but they redirect ALL!

RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(.*)$ http://www.myanotherdomain.com/$1 [L,NC]  

在这些行之前,我有很多这样的行(我正在使用MVC(模型,视图,控制器)):

Before these lines, I have a lot of lines like this (I'm using MVC (Model, View,Controller)):

RewriteRule ^car/brand/?$ ?controller=Car&action=viewBrand [L,NC]  

会发生什么:

它与不存在的文件兼容,但似乎与MVC规则不兼容.这些规则必须匹配,然后停止评估规则,因为de"L"标志.但是它似乎会继续评估规则,最后评估重定向规则.结果是这样的:

What happens:

It works wells with non existing files, but seems to be imcompatible with the MVC rules. These rules have to match and then stop evaluating rules because de "L" flag. But it seems to continue evaluation of the rules and finally evaluates the redirect rule. The result is this:

http://www.mydomain.com/car/brand/

http://www.myanotherdomain.com/?controller=Car&action=viewBrand

请问有人可以帮我吗?

非常感谢

乔纳森

推荐答案

尝试一下:

RewriteCond %{REQUEST_FILE} !-f
RewriteRule ^(.*)$ http://www.myanotherdomain.com/$1 [QSA,R,L]

另请参见:​​如果未找到文件/文件夹,则为mod重写目录

这篇关于如果文件不存在,则将Mod重写重定向到另一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆