0

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 for it.

Thanks

sammy_jacob
  • 195
  • 1
  • 1
  • 6

2 Answers2

0

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?

Community
  • 1
  • 1
Brant
  • 5,721
  • 4
  • 36
  • 39
0

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.

solartic
  • 4,249
  • 3
  • 25
  • 26
  • does django url support #! in URL? – sammy_jacob May 13 '11 at 15:48
  • 1
    As pointed out by Brant anything after the number sign is generally ignored. Therefore it is generally used in combination with JavaScript to create ajax based websites. If what you want is to redirect users to the correct ajax version of the URL if they make an incorrect guess, then my answer should help. Otherwise, Brant answer seem best. – solartic May 13 '11 at 16:26