crmepham
crmepham

Reputation: 4740

Is this the correct xml regex for URL?

I am implementing urlReWriter into my Java web project.

I want to change this url: /read-post.jsp?id=1&title=some-cool-blog-title

into this shortened/cleaner url: /read-post/1/some-cool-blog-title

This is the rule I have implemented:

<rule>
   <from>^/read-post/([0-9]+)/([0-9][a-z][A-Z]+)</from>
   <to>/read-post.jsp?id=$1&amp;title=$2</to>
</rule>

The problem is it isn't re writing the url and I suspect it is because the xml regex I've used is incorrect?

How do i format it correctly when there can be any number for the id and any number, character or special character - for the title?

Upvotes: 1

Views: 67

Answers (1)

Volker Stampa
Volker Stampa

Reputation: 849

Your regular expression for the title ([0-9][a-z][A-Z]+) is for sure not correct since the + refers to the [A-Z] only. In addition to this the - your are mentioning in the question is missing. You could try this instead: ([0-9a-zA-Z\-]+)

Upvotes: 1

Related Questions