开发者

Apache Rewrite Rule (Regex)

I'm using apache and i need to rewrite URL of type:

/a/b/c/d/boundary/stuff*

to:

/boundary/a_b_c_d/stuff*

I need to rewrite the first Uri to the second format.

The number of elements before '/boundary' are variable and i want to replace all slashes('/') between elements by '_'

The boundary word is always the same.

I believe i need to do make two rules, one for slash replace and another to change boundary to the beginning of the URL:

The second rule i think is something like ^/(.*?)/\bboundary\b to /boundary/$1

Is it possible to achieve what i want ?!

How?!

Thank you.

EDIT

I want to match until first boundary word, it's possible to have a URL like

/a/b/c/d/boundary/boundary

EDIT

Gumbo thank yo开发者_如何学Pythonu for your help

based on your rewrite rules i managed to create one.


Try these rules:

RewriteRule ^/([^/]+)/(.+)/boundary/([^/]+)$ /$1_$2/boundary/$3 [N]
RewriteRule ^/([^/]+)/boundary/([^/]+)$ /boundary/$1/$2 [L]

Be careful with the first rules with the N flag causes an internal rewrite without incrementing the internal counter. So chances are that you have infinite recursion.


Edit    After you’ve changed your question:

RewriteCond $1 !=boundary
RewriteCond $2 !=boundary
RewriteRule ^/([^/]+)/([^/]+)(/.*)?$ /$1_$2$3 [N]
RewriteRule ^/([^/]+)/boundary(/.*)$ /boundary/$1$2 [L]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜