Reputation: 5
I know this topic has been covered in lot of question but i could not find the right answer to my the issue i am facing. So it goes like this
I have a URL like this
localhost:8080/web/Area.jsp?name=food
I want to achieve the following for better SEO
localhost:8080/web/food-loc-hyd
Note:
food is a input which has 1000's of variants like apple,dish,etc.
-loc-hyd is a static keyword and is added to every food
I tried URL rewrite filter from tuckey but I am not getting the correct combination. My name parameter above has thousands of different variables which can be given as input, so I tried something like this.
<rule><from>^/*-loc-hyd</from>
<to>/Area.jsp?name=*</to></rule>
I have a similar request which needs to be cleaned up which looks like this
from:
localhost:8080/web/Area.jsp?name=food&address=ind
to:
localhost:8080/web/food-loc-hyd/ind
Please guide on how to go about it.
Thanks , I am off to a start. I have done the above and its working to an extent. My navigation is like breadcrumbs structure so it goes like this
localhost/web/loc where loc is a variable so I have the following and it works:
Rule 1:
<from>^/([^-]+?)</from>
<to>/Area.jsp?name=$1</to>
Now when a user is on /hyd, I am sending him to /hyd/app and then to /hyd/app/lic where in both app and lic are variables so I did something like this:
Rule 2:
<from>^/([^-]+?)/([^-]+?)</from>
<to>/app.jsp?name=$1&app=$2</to>
Rule 1 and Rule 2 are working, but rule 3 below is not working, it is being handled by the rule 1.
Rule 3:
<from>^/([^-]+?)/([^-]+?)/([^-]+?)</from>
<to>/lic.jsp?name=$1&app=$2&lic=$3</to>
Any ideas where I am not doing it correctly.
Upvotes: 0
Views: 2142
Reputation: 5
I have got the solution, I changed the order in urlrewrite.xml and have implemented it on my site http://www.citypincode.in
This is order which I have done in urlrewrite.xml and it is working fine:
<from>^/([^-]+?)/([^-]+?)</from>
<to>/app.jsp?name=$1&app=$2</to>
<from>^/([^-]+?)</from>
<to>/Area.jsp?name=$1</to>
<from>^/([^-]+?)/([^-]+?)</from>
<to>/app.jsp?name=$1&app=$2</to>
Thanks for the help.
Upvotes: 0
Reputation: 8659
Url rewrite filters work via regex, and you need capture groups for the variables, not just a star.
Something like:
<rule>
<from>^/([^-]+?)-loc-hyd/(.+?)$</from>
<to>/Area.jsp?name=$1&address=$2</to>
</rule>
If you don't understand what that means, you need to study up on the regex syntax for Java.
Upvotes: 1