문제

I'm using rack-rewrite to add a url rewrite rule that will strip slashes, but I only want it to do it if there isn't a hashbang following the slash.

I tried the following regex, but it rewrites anyway, even if there is a #! after the /:

^/(?!#!.*)(.*)/$

# The rule
r301 %r{^/(?!#!.*)(.*)/$}, '/$1'

As an example, if the url would be tada/, it should rewrite to tada, but if it were tada/#!WHATEVER_STRINGS_HERE it should not enforce the rule. What is my regex missing ?

도움이 되었습니까?

해결책

You may be missing that URL fragments (a # and everything following it) are never submitted to the server at all. When the browser is asked to visit the URL /foo/bar#baz, it will only request /foo/bar from the server and handle the #baz locally inside the retrieved document.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top