English 中文(简体)
url-reformation how to reconize when a part of url is numeric or num+words
原标题:url-rewriting how to reconize when a part of url is numeric or num+words

i) 难以确定这种ur改法

RewriteRule ^([aA-zZ0-9_-]+)/?([0-9]*)/?([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)/?$ index.php?m=$1&r=$2&a=$3&b=$4 [QSA]

它很好地完成了这些工作:(打断和鞭)......”

Test/1234/gotoA/gotoB/
Test/1234/gotoA/
Test/1234/
Test/gotoA/gotoB/

问题何时发生。 一开始是几个例子:

Test/123gotoA 

返回:

index.php?m=Test&r=123&a=gotoA&b=

如何确定?

最佳回答

The problem is that you make the / optional. It is the whole of /(xxx) which should be made optional.

为此:

RewriteRule ^([aA-zZ0-9_-]+)(?:/(d+))?(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?/?$  index.php?m=$1&r=$2&a=$3&b=$4 [QSA]

如果我们以<条码”取代你原来的规章。 测试/123gotoA作为投入,这里的情况是:

#before first match
regex: |^([aA-zZ0-9_-]+)/?([0-9]*)/?([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)/?$
input: |Test/123gotoA
# ^
regex: ^|([aA-zZ0-9_-]+)/?([0-9]*)/?([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)/?$
input: |Test/123gotoA
# [aA-zZ0-9_-], once or more, captured: $1 is "Test"
regex: ^([aA-zZ0-9_-]+)|/?([0-9]*)/?([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)/?$
input: Test|/123gotoA
# /?: a / is found
regex: ^([aA-zZ0-9_-]+)/?|([0-9]*)/?([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)/?$
input: Test/|123gotoA
# [0-9], zero or more times, captured: $2 is "123"
regex: ^([aA-zZ0-9_-]+)/?([0-9]*)|/?([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)/?$
input: Test/123|gotoA
# /?: no /, but satisified, since ? can match zero times
regex: ^([aA-zZ0-9_-]+)/?([0-9]*)/?|([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)/?$
input: Test/123|gotoA
# [A-Za-z0-9_-], zero or more times, captured: $3 is "gotoA"
regex: ^([aA-zZ0-9_-]+)/?([0-9]*)/?([A-Za-z0-9_-]*)|/?([A-Za-z0-9_-]*)/?$
input: Test/123gotoA|
# /?: no /, but satisified, since ? can match zero times
regex: ^([aA-zZ0-9_-]+)/?([0-9]*)/?([A-Za-z0-9_-]*)/?|([A-Za-z0-9_-]*)/?$
input: Test/123gotoA|
# [A-Za-z0-9_-], zero or more times, captured: $4 is ""
regex: ^([aA-zZ0-9_-]+)/?([0-9]*)/?([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)|/?$
input: Test/123gotoA|
# /?: no /, but satisified, since ? can match zero times
regex: ^([aA-zZ0-9_-]+)/?([0-9]*)/?([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)/?|$
input: Test/123gotoA|
# $: satisified, since this is the end of input
regex: ^([aA-zZ0-9_-]+)/?([0-9]*)/?([A-Za-z0-9_-]*)/?([A-Za-z0-9_-]*)/?$|
input: Test/123gotoA|
# end of match: success

如今,经改写后,情况不同:

# before first match
regex: |^([aA-zZ0-9_-]+)(?:/(d+))?(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?/?$
input: |Test/123gotoA
# ^
regex: ^|([aA-zZ0-9_-]+)(?:/(d+))?(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?/?$
input: |Test/123gotoA
# [aA-zZ0-9_-], one or more times, captured: $1 is "Test"
regex: ^([aA-zZ0-9_-]+)|(?:/(d+))?(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?/?$
input: Test|/123gotoA
# Try and find /, then one or more digits, zero or one time: match, $2 is "123"
regex: ^([aA-zZ0-9_-]+)(?:/(d+))?|(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?/?$
input: Test/123|gotoA
# next group: a / must be found, but the next character is "g": backtrack, $2 is now "12"
regex: ^([aA-zZ0-9_-]+)(?:/(d+))?|(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?/?$
input: Test/12|3gotoA
# but here again the next character is not a /: the engine must backtrak again, until:
regex: ^([aA-zZ0-9_-]+)(?:/(d+))?|(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?/?$
input: Test|/123gotoA
# (?:/(d+))? is still satified, as it is optional, and $2 is now ""
# Next group: /, followed by [a-zA-Zd_-] one or more times, captures: $3 is "123gotoA"
regex: ^([aA-zZ0-9_-]+)(?:/(d+))?(?:/([a-zA-Zd_-]+))?|(?:/([a-zA-Zd_-]+))?/?$
input: Test/123gotoA|
# Next group: same as second, but satisfied with an empty match: $4 is ""
regex: ^([aA-zZ0-9_-]+)(?:/(d+))?(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?|/?$
input: Test/123gotoA|
# an optional /: satisified
regex: ^([aA-zZ0-9_-]+)(?:/(d+))?(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?/?|$
input: Test/123gotoA|
# end of input: satisified
regex: ^([aA-zZ0-9_-]+)(?:/(d+))?(?:/([a-zA-Zd_-]+))?(?:/([a-zA-Zd_-]+))?/?$|
input: Test/123gotoA|
# Match
问题回答

暂无回答




相关问题
URL rewrite in IIS6 - Third party tools

I have collected the following api/sdk/whatever which provide modules for doing url rewriting in IIS 5/6/7. Some are free-open source and some require $. I haven t tried any of them. I would like to ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

ASP.NET Friendly URLs

In my research, I found 2 ways to do them. Both required modifications to the Application_BeginRequest procedure in the Global.Asax, where you would run your code to do the actual URL mapping (mine ...

Could I get by HttpModule the URL that contains * before?

My web-site is working under ASP.NET 3.5, IIS7, Integrated pipiline mode. My HttpModule is getting request to all resources, including URLs like this: http://my-site.com/address And I would support *...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

URL Mod-Rewrite

I currently have a working URL: http://example.com/security-services.php?service=fixed-camera-surveillance and then I have PHP say, $_REQUEST[ service ] to do some stuff... But I d like to ...

热门标签