Welcome Guest, Not a member yet? Register   Sign In
A SLASH problem of relative href value
#1

(This post was last modified: 01-31-2016, 10:03 PM by dangyuluo.)

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.
Reply
#2

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

RewriteRule ^(.*)/$ $1 [R=301,L]
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB