Welcome Guest, Not a member yet? Register   Sign In
Links in page source OK but incorrect URLs in browser.
#1

[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
appearing in the status bar of Firefox and clicking on it Firefox tries to "take me" to this incorrect URL.

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>
    RewriteEngine On
    RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /wccs/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /wccs/index.php
</IfModule>

I have also tried the htaccess from
Code:
http://codeigniter.com/wiki/mod_rewrite/
which I've changed to reflect my setup as follows...
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wccs

    RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

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

[eluser]verynewtothis[/eluser]
Are you using 'anchor' to reference your local site urls?
Code:
echo anchor('home/display_topic/1', 'title="Test Link"');
#3

[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');
which works fine.

Option 2:
Code:
echo anchor('news/local/123', 'My News', array('title' => 'The best news!'));
which works fine.

However, Option 3:
Code:
echo anchor('news/local/123', 'title="My News"');
is supposed to produce...
Code:
<a href="http://example.com/index.php/news/local/123" title="My News">My News</a>
but actually produces...
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.
#4

[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).




Theme © iAndrew 2016 - Forum software by © MyBB