CodeIgniter Forums
A SLASH problem of relative href value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: A SLASH problem of relative href value (/showthread.php?tid=64253)



A SLASH problem of relative href value - dangyuluo - 01-31-2016

When using a relative A link, there seems to be a little problem.
Assume there is a page whose url is http://www.site.com/user/index. And normally we can also visit it through http://www.site.com/user/index/, with a slash in the end. Though CodeIgniter could handle it elegantly, showing the correct page content, the browser wrongly regards these two pages as in two different folders.

If I'm using a relative A link in this page, like <a href='order'></a>. When people visiting the URL without slash in the end, they can be led to http://www.site.com/user/order which is the correct path, cause the browser will try to find order within the same folder of index.

But, here comes the problem, if the users visit the page with a slash in the end, and if they click the A link, they will be led to http://www.site.com/user/index/order. Now the browser will try to find order in the tub-folder of index.

I know site_url() can generate an absolute path of link. But it's neither elegant nor traffic-consuming. So does anybody come up with a solution of this problem? Thanks.


RE: A SLASH problem of relative href value - InsiteFX - 02-01-2016

You can add this to your .htaccess file to remove the ending slash from your url's.

RewriteRule ^(.*)/$ $1 [R=301,L]


RE: A SLASH problem of relative href value - dangyuluo - 02-01-2016

(02-01-2016, 04:48 AM)InsiteFX Wrote: You can add this to your .htaccess file to remove the ending slash from your url's.

RewriteRule ^(.*)/$ $1 [R=301,L]

That's also an elegant solution. Thank you! Big Grin