Routing URLs and trailing slashes |
Hello,
I have a little problem with codeigniter because I want to have urls like that http://site.com/dogs/ or http://site.com/cats/ etc. So see my routes.php file : PHP Code: $route['([0-9a-zA-Z-_+]+)'] = "site/categorie/$1"; My htaccess file : Code: RewriteCond %{REQUEST_FILENAME} !-f My urls are working but I can access with this url http://site.com/dogs/ and this url http://site.com/dogs But it's a big problem for duplicate content in SEO. I already tried : PHP Code: $route['([0-9a-zA-Z-_+]+)/'] = "site/categorie/$1"; But it's doesn't work... I am looking for a solution to for using trailing slashes for my urls. Thank you for you help.
Try this htacces, with your first roule e.g.:
PHP Code: RewriteCond %{REQUEST_FILENAME} !-f
In your e.g. you dont need a route. If you have the dogs controller with an index method and no parameter you can deactivate your route. Then your links should work.
03-26-2015, 03:21 AM
(This post was last modified: 03-26-2015, 03:22 AM by Avenirer. Edit Reason: forgot something... ) (03-26-2015, 03:21 AM)Avenirer Wrote: did you try this? ... or rather this: Code: RewriteRule ^(.*)/?$ index.php?/$1/ [L] Your rule would rejected requests that have a trailing slash. Edit: Actually, the OP's goal seems to be indeed to reject such requests. However, 'foo' being redirected to 'foo/' is not the same as both of them just returning the same content. Search engines should understand redirects and still only track 'foo/'.
The problem is that I need urls like that mypage.html and mycategorie/, I need both.
So look my my complete routes.php PHP Code: $route['default_controller'] = "site"; Code: RewriteCond %{REQUEST_FILENAME} !-f Changing my htaccess doesn't change nothing I still have the same probleme, I can access to my page : http://site.com/categorie/ and http://site.com/categorie There is any redirection. I don't like my last roule : PHP Code: $route['([0-9a-zA-Z-_+]+)'] = "site/categorie/$1"; // for my pages like that categorie/ But I see any other solution to make my categories like that categorie1/, categorie2/
If the only purpose is SEO:
1. Add a canonical link to your document head: http://moz.com/learn/seo/canonicalization 2. As much as possible, only use the canonical URLs when linking/redirecting within your own site.
Canonicale is a solution yes, but there isn't any solution with codeigniter routes and htaccess ?
|
Welcome Guest, Not a member yet? Register Sign In |