![]() |
Mod rewrite force trailing slashes & form_open() - site_url() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Mod rewrite force trailing slashes & form_open() - site_url() (/showthread.php?tid=59569) |
Mod rewrite force trailing slashes & form_open() - site_url() - El Forum - 10-21-2013 [eluser]35mm[/eluser] It's a good idea to use mod rewrite to force www. and trailing slashes on (or off) your URLs to avoid duplicating content as www.site.com/controller/method/ and www.site.com/controller/method and http://site.com/controller/method/ and http://site.com/conroller/method give four duplicates of the same content which the search engines will mark you down for. However, after I set up the mod rewrite I noticed I could no longer login to the site and other post forms were failing too. It took me a while to figure out that CI was removing the trailing slash when using Code: form_open('controller/method/') The method in that thread is undoubtedly handy if you have an existing site with loads of post forms, and have just added the mod rewrite, and need a quick fix. However, hacking CI's core in my opinion, should be a last resort and isn't an elegant solution unless it's a bug fix or absolutely necessary. One alternative is to manually code your forms, but CI's form_open is very convenient and saves time especially if you are using CSRF. So I came up with a simple fix that I'll share here in case it helps anyone else who runs into this problem. The solution: while coding your app, simply add a hash after the trailing slash like so Code: form_open('controller/method/#') |