简体   繁体   中英

Can only navigate to a page once, then I receive 404

Earlier I had someone help me with a .htaccess issue so that I could remove index.php from the url. However, while that seemed to work, I'm not sure if it fully worked unless it's something I'm doing wrong (likely - new to PHP/CI/WAMP, just started writing this Friday).

I'm using CI and WAMP on a Windows 7 machine. Here's my .htaccess :

RewriteEngine on
RewriteCond $1 !^(index\.php|css)
RewriteRule ^(.*)$ index.php/$1 [NC,L]

The base url that I go to to see the site is:

localhost/forum/

I have some menu items across the top. One them them is Forum and when it's written out, the link is:

<a href="<?php echo base_url(); ?>

I do not have the base_url set in my config file. But when I hover over the link, it shows:

localhost/Forum/

When I inspect the element in Chrome it shows:

<a href="http://localhost/Forum/">

I have a div that is a link to what will be a sub-forum. In the html, it's written as:

<a href='$record->name/'>

When I hover over the div, it shows that it will go to:

localhost/Forum/Site/

When I inspect the element it says it is going to:

<a href="Site/">

Now, for a minute there, I could start up Mozilla or Chrome, click on Site and it would go to where I wanted it to. I could then click on Forum and it would go back. But if I clicked on Site again, it would go to a 404 page. Then if I closed the browser and opened it back up, it would work again one time through, then do the same thing. I have NO idea what is going on here. As I was typing this, I set my base url to http://localhost/Forum and even that didn't do anything.

UPDATE

I edited my base_url and fixed the issue. I was forgetting a / at the end.

Use site_url() instead. base_url() is primarily used for linking to media such as Javascript and CSS.

ie

<a href="<?= site_url('forum'); ?>">Forum</a>

or

<a href="<?= site_url('forum/' . $Category->CategoryID . '/' . url_title($Category->Title)); ?>"><?= $Category->Title; ?></a>

See http://codeigniter.com/user_guide/helpers/url_helper.html for more information.

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM