How to organize country/state/city browsing in codeigniter url

后端 未结 1 886
一个人的身影
一个人的身影 2020-12-22 03:38

I\'m creating a website that includes a country/state/city browsing interface. For SEO purposes, I want to include the name of the country/state/city in the URL. For exampl

相关标签:
1条回答
  • 2020-12-22 04:17

    Edit the routes.php file located in your config folder.

    As noted in the link from Bora (CI URI Routing) Some examples from the documentation:

    $route['journals'] = "blogs";
    //A URL containing the word "journals" in the first segment will be remapped to the "blogs" class.
    
    $route['blog/joe'] = "blogs/users/34";
    //A URL containing the segments blog/joe will be remapped to the "blogs" class and the "users" method. The ID will be set to "34".
    

    In your case you need to reconcile the names of the functions in your controllers and the desired URL names. You could end up with the examples that you show in your question, but you'd have to lay out a route for every country that you want in the first URI segment after domain.com. It's probably easier to do this:

    http://www.domain.com/locations/USA/NewYork?Category=car&color=black&Model=2009&page=5

    And then in your routes folder:

    $route['locations/(.*)/(.*)'] = 'locations';
    

    If you need to pass additional parameters to your controller via URL you can use query strings as you show above, or add

    $route['locations/(.*)/(.*)/([0-9]{1,5})'] = 'locations/$1';
    //assumes that parameter is numeric, 0-9 up to 5 digits
    
    0 讨论(0)
提交回复
热议问题