Want to turn example.com/country/name/Korea to example.com/korea
I think the title explains it all. The thing is that my application is Zend Framework based and includes a number of controllers. The main controllers are:
Companies/
People/
Countries/
Initially a country profiles url could ve accessible via a url like:
example.com/countries/view/id/Korea
I shorted it by adding a router to
example.com/countries/Korea
However the client requires a further shortening to:
example.com/Korea
Bringing the name of the country which is in this case a url parameter in the place of the controller. Plus the clients requires that all the urls be shortened in a similar fashion so then a url for a company which used to read something like:
example.com/companies/acme-corporation-1234
开发者_C百科
where 1234 is the id of the company to read something on the lines of:
example.com/acme-corporation-company
I can understand uniqueness of country names as there aren't any two countries with similar names however I doubt I can accomplish the same for companies as you can have a number of companies with similar names. I checked out Gogobot.com and noticed that all of the urls on the site are really easy to read and don't even include a single id number anywhere.
Is there any idea on how this can be done i.e further shortened - so that example.com/korea doesn't mean Korea as a controller but as a link to example.com/countries/korea and likewise the url example.com/countries should still be interpreted as a call to countries controller.
Please take a look at the similar problem one of the poster. You could use Apache's RewriteMap
to map URL to external script and process the request based on the code.
That way, you don't have to worry about having a controller for each country, but pass it to the script to find the ID or anything that you want them to process.
Mod_ReWrite / ReWriteMap a URL using a database lookup script
If you're reasonably comfortable with ZF you can use a custom route class for this, see this explanation: http://tfountain.co.uk/blog/2010/9/9/vanity-urls-zend-framework (slightly different problem there but the solution is the same). For your case you'll want one for companies and one for countries.
精彩评论