![]() |
Links in page source OK but incorrect URLs in browser. - 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: Links in page source OK but incorrect URLs in browser. (/showthread.php?tid=33008) |
Links in page source OK but incorrect URLs in browser. - El Forum - 08-12-2010 [eluser]Unknown[/eluser] Hi I'm trying to code my first Codeigniter 1.7.2 application and have run into a weird problem. I've created a view which displays some relative urls like this Code: home/display_topic/1 I've checked using the browser's "page source" command that the URL's are OK and as above. However, when I mouse over a link I get Code: http://localhost/wccs/home/display_forum/home/display_topic/1 I have a separate view that works fine with it's anchor links being correctly displayed in page source and in Firefox. As I try and click around the site the URL's go crazy getting longer and longer like this Code: http://localhost/wccs/home/display_forum/home/display_topic/home/display_forum/home/display_forum/home/display_forum/2 Could it have anything to do with my .htaccess file which is as follows... Code: <IfModule mod_rewrite.c> I have also tried the htaccess from Code: http://codeigniter.com/wiki/mod_rewrite/ Code: <IfModule mod_rewrite.c> But the problem doesn't seem to be here. The problem is the same in Internet Explorer 8 as well as Firefox. Thanks for your help Links in page source OK but incorrect URLs in browser. - El Forum - 08-12-2010 [eluser]verynewtothis[/eluser] Are you using 'anchor' to reference your local site urls? Code: echo anchor('home/display_topic/1', 'title="Test Link"'); Links in page source OK but incorrect URLs in browser. - El Forum - 08-12-2010 [eluser]Unknown[/eluser] Hi there verynewtothis. Thanks for your reply and your suspicions were right - I was doing Code: echo '<a href="/home/display_topic/'.$id.'">Test Link</a>'; I've changed this using anchor() as you suggest to Code: echo anchor("home/display_topic/$id", 'Test Link'); and that seems to be working and generating URLs in the browser that match my page source. I've had a look at the URL helper documentation and have come across another problem. Could there some settings somewhere that affect anchor()? This is the problem. anchor() can be used in 3 ways... Option 1: Code: echo anchor('news/local/123', 'My News'); Option 2: Code: echo anchor('news/local/123', 'My News', array('title' => 'The best news!')); However, Option 3: Code: echo anchor('news/local/123', 'title="My News"'); Code: <a href="http://example.com/index.php/news/local/123" title="My News">My News</a> Code: <a href="http://example.com/index.php/newslocal/123">title="My title"</a> This is not a major problem as Option 2 can be used instead. But it's puzzling how things don't work like the documentation mentions. Unless, of course, there is something screwed up in my configuration files. Thanks for your help. Links in page source OK but incorrect URLs in browser. - El Forum - 08-12-2010 [eluser]verynewtothis[/eluser] You are probably correct about option3 not working as identified in docs. I usually prefer to use option 1 (simplest) or option 2 (more control using arrays). |