为什么我的服务器路由被附加到所有超链接的开头?
我最近开始摆弄 CodeIgniter,并在通过 HTML 或使用锚函数执行标准超链接时遇到了问题,因为所有超链接都会在开头附加我的服务器路由。举例来说,我在我的视图中编写了一个标准超链接,例如 Test site
它将返回 http: //localhost/test/index.php/test/www.testsite.com
当我单击链接时? 我不确定我做错了什么,但猜测这可能与路由有关?
I have recently started messing round with CodeIgniter and ran into problems when doing standard hyperlinks through either HTML or using the anchor function, as all hyperlinks append my server route on the start. So say for example I had written a standard hyperlink in my view such as <a href="www.testsite.com">Test site</a>
it would return http://localhost/test/index.php/test/www.testsite.com
when I click the link?
I'm not sure what I'm doing wrong, but guessing it maybe something to do with routing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是你没有在你的视图中的链接前面添加协议。您的浏览器假设
www.testsite.com
是一个内部链接,并以与对待test/path/to/resource.php
完全相同的方式对待它(作为相对链接)。将
http://
添加到您的 URL 前面(在视图代码中),一切都应该正常工作。The problem is that you have not added the protocol in front of the link in your view. Your browser is assuming that
www.testsite.com
is an internal link and treating it exactly the same as it would treattest/path/to/resource.php
(as a relative link).Add an
http://
to the front of your URL (in the view code) and everything should just work.听起来您使用 url 帮助器并将链接添加到 site_url() url 函数之上。您可以发布您在视图中使用的代码吗?
It sounds like your using the url helper and adding your link ontop of the site_url() url function. Can you post your the code your using in your view?