-->

Can I have SEO friendly urls in Struts?

2019-07-08 09:28发布

问题:

I want to have SEO friendly urls in my application, which will be built in java/j2ee using Struts (1/2).

I have some classifications as follows

county/countryname
county/state/statename
county/state/locality/localitname

I guess above URLs will be seo friendly?

How can I have such URLs with Struts instead of something like /county='xyz' ?

回答1:

use urlrewrite library, it will integrate nicely with most of the java web frameworks.

example from here:

In the following example requests for /world/usa/nyc will be transparently forwarded to /world.jsp?country=usa&city=nyc

<rule enabled="true">
   <from>^/world/([a-z]+)/([a-z]+)$</from>
   <to>/world.jsp?country=$1&amp;city=$2</to>
</rule>


回答2:

You can use Apache mod_rewrite, it will convert your URLs like http://myapp.com/u/nishant/page/account/tab/3 to http://myapp.com?u=nishant&page=account&tab=3. So, your app don't need to worry about how URL structure.

Alternatively, you may use URLRewriteFilter, which is nothing but a cleverly written filter that need to the first filter of your application and all the requests should pass through this. It follows the same pattern rules as Apache mod_rewrite.



回答3:

I don't think this can be done with Struts. You'll need Filters in order to achieve this.