开发者

Attempt to rewrite a page not found before displaying 404 error message

The rails codebase that I'm working on supports two web applications, and we use apache to rewrite the url intelligently when a user comes to our domain, so for example if you approach our site from

app_name.domain_name.com

it is rewritten to

app_name.domain_name.com/app_name

and our nested routes are called. This is a recent change to our app however, and (obviously) some bookmarks aren't forwarding properly. What I'd like to do is modify our routes (or maybe add a small piece of middleware) which attempts tot rewrite to the correct开发者_如何学C url rather than displaying a 404 message.

That is to say, if a customer tries to view

app_name.domain_name.com/controller/action

our nested routes miss the call, and instead of 404ing, the app rewrites the request to:

app_name.domain_name.com/app_name/controller/action

Can I do this with either a clever route, or with some middleware? If not, can this be done with apache rewrites?

Thanks


Try this

RewriteCond %{HTTP_HOST} ^web_app.benchmark.company.net$ [NC]
RewriteRule ^/?(.*) /web_app/$1 [L,R=permanent]

(Note that I have not tested this)

I recommend you read the Apache rewrite guide.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜