[英]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. 早些时候,有人帮助我解决
.htaccess
问题,以便可以从URL中删除index.php
。 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). 但是,尽管这似乎可行,但除非我做错了什么,否则我不确定它是否能完全正常工作(可能是PHP / CI / WAMP的新功能,本周五才开始编写)。
I'm using CI and WAMP on a Windows 7 machine. 我在Windows 7计算机上使用CI和WAMP。 Here's my
.htaccess
: 这是我的
.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: 我要查看该站点的基本URL是:
localhost/forum/
I have some menu items across the top. 我在顶部有一些菜单项。 One them them is
Forum
and when it's written out, the link is: 其中一个就是
Forum
,当它写出来时,链接是:
<a href="<?php echo base_url(); ?>
I do not have the base_url set in my config file. 我的配置文件中没有设置base_url。 But when I hover over the link, it shows:
但是当我将鼠标悬停在链接上时,它显示:
localhost/Forum/
When I inspect the element in Chrome it shows: 当我检查Chrome中的元素时,它显示:
<a href="http://localhost/Forum/">
I have a div that is a link to what will be a sub-forum. 我有一个div,它是到子论坛的链接。 In the html, it's written as:
在html中,它写为:
<a href='$record->name/'>
When I hover over the div, it shows that it will go to: 当我将鼠标悬停在div上时,它表明它将转到:
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. 现在,在那里等待一分钟,我可以启动Mozilla或Chrome,单击“网站”,它会转到我想要的位置。 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.
但是,如果我再次单击“网站”,它将转到404页。 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. 在键入此内容时,我将基本URL设置为
http://localhost/Forum
,即使那样也没有执行任何操作。
I edited my base_url and fixed the issue. 我编辑了base_url并解决了该问题。 I was forgetting a
/
at the end. 我忘记了
/
末尾。
Use site_url()
instead. 使用
site_url()
代替。 base_url()
is primarily used for linking to media such as Javascript and CSS. base_url()
主要用于链接到Javascript和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. 有关更多信息,请参见http://codeigniter.com/user_guide/helpers/url_helper.html 。
HTH 高温超导
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.