开发者

Is it better to use routes or mod_rewrite to forward old URLs?

I recently changed some URLs in my Rails app and am curious if I'm bett开发者_如何学Goer off using routes + controllers + redirect_to to forward the old URLs, or just use .htaccess with Apache's mod_rewrite?

I'm using Apache + Passenger so htaccess files work, but was curious if there was a standard for this sort of thing.

FWIW, the URLs were changed from this: http://example.com/user/joeschmoe

to this: http://example.com/joeschmoe


Using mod_rewrite will undoubtedly give the best performance because the request won't even touch Rails. However, there is a third way if you find mod_rewrite to be a bit of a pain to get working—as I do—and a maintenance burden.

Refraction is Rack middleware designed to replace mod_rewrite. It lets you write your rewrite rules using good old readable Ruby code and it's still faster than using Rails itself for the task.


I personally would perform the rewrite using mod_rewrite, because it should be faster than loading rails and performing a redirect there.

If you're really concerned about performance (and you manage your own webserver), you could build the rewrite rules (and whatever else you have in your .htaccess) into the httpd.conf file and disable overrides (disabling your .htaccess files). This will give you a slight performance boost in serving all of your requests.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜