开发者

redirect rule for nginx?

I am running my django app using nginx. I want to write a redirect rule such that if user hit the url http://example.com/django/nginx/ then it redirect it to http://example.com/django/#!/nginx/. I want o know the regex f开发者_如何学Cor it.

Thanks


You'll want to handle this on the client side (through Javascript, most likely), not through nginx.

From what I understand, the point of # in URLs (as per the spec) is that the portion that comes after # doesn't reach the server.

Also, see this question for some info on JS libraries for working with hash-bang urls: Are there any javascript libraries for working with hashbang/shebang (#!) urls?


Given you example I'm assuming that you are working with URLs in the form "http://1/2/3/" only, so nothing going beyond 3. Where you want to separate 2 and 3 with "/#!/". If that is the case you can try the following.

from django.views.generic.simple import redirect_to

urlpatterns = patterns('',
    ('^django/(?P<ajax_section>\w+)/$', redirect_to, {'url': '/django/#!/%(ajax_section)s/'}),
)

The above assumes that 2("django") in the URL will be fixed. If that is not the case you will have to try and make it a parameter as well.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜