doufu5521
2017-12-25 00:49
浏览 137
已采纳

codeigniter中资产的404 / net :: ERR_ABORTED错误

I'm working through my first Codeigniter webpage, and I've run into a few peculiarities. The first is that I haven't needed to use base_url or site_url in front of my URLs to get them to work, at least not originally. I set up the main page, and simply did

<link href="assets/css/bootstrap.min.css" rel="stylesheet" />

and this seemed to automatically add the domain name in front of it. I'm not sure how it worked, but it works for all the URLs like it. When I look at the inspect window, it shows like this. I don't know if this is relevant, but I wanted to make note of it.

The issue was on my second page. I added a new controller named Admin, and set it to bring up a different page. I set up the URLs in the same way I did before, but when I loaded it, the CSS and Javascript didn't load. In case it matters, I tried loading it by doing Domainname.com/Admin. The html loads correctly, but when I looked at the console, it gave me a net::ERR_ABORTED and 404 errors for my images and files. I've double checked all of them, and they are all in the correct spot. I found this page: 404 page not found error in Codeigniter and tried using the solution there in my .htaccess file. It not only didn't work, but now the original page that was working correctly refuses to load up any of the asset files. I tried removing the new line of code, but it still will not work correctly, even though everything is the exact same way it was before.

Here is my .htaccess folder:

RewriteEngine On
RewriteBase /eventCentral/

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d

#RewriteCond $1 !^(index\.php|assets)

RewriteRule ^ index.php [QSA,L]

I tried removing the commented piece of code completely, but it still didn't fix it.

My file structure is also correct, and can be seen here.

As I said, I'm still very new to code igniter, so if answers can be broken down Barney style, I'd appreciate it. I've also tried looking through a number of stack overflow questions that seemed relevant, and I still haven't found a solution that works.

图片转代码服务由CSDN问答提供 功能建议

我正在通过我的第一个Codeigniter网页,我遇到了一些特点。 首先,我不需要在我的URL前面使用base_url或site_url来使它们工作,至少不是最初的。 我设置了主页面,只需

 &lt; link href =“assets / css / bootstrap.min.css”rel =“stylesheet”/&gt; 
    
 
 

这似乎会自动在其前面添加域名。 我不确定它是如何工作的,但它适用于所有类似的URL。 当我查看检查窗口时,它显示为。 我不知道这是否相关,但我想记下它。

问题发生在我的第二页。 我添加了一个名为Admin的新控制器,并将其设置为显示不同的页面。 我以与之前相同的方式设置URL,但是当我加载它时,CSS和Javascript没有加载。 如果它很重要,我尝试通过Domainname.com/Admin加载它。 html加载正确,但是当我查看控制台时,它给了我一个 net :: ERR_ABORTED和 我的图片和文件有404错误。 我仔细检查了所有这些,他们都在正确的位置。 我找到了这个页面: Codeigniter中找不到404页错误并尝试过 在我的.htaccess文件中使用解决方案。 它不仅没有工作,而且现在正常工作的原始页面拒绝加载任何资产文件。 我尝试删除新的代码行,但它仍然无法正常工作,即使所有内容都与以前完全相同。

这是我的.htaccess文件夹:

  RewriteEngine On 
RewriteBase / eventCentral / 
 
RewriteCond%(REQUEST_FILENAME)!- f  
RewriteCond%(REQUEST_FILENAME)!-d 
 
#RewriteCond $ 1!^(index \ .php | assets)
 
RewriteRule ^ index.php [QSA,L] 
   \  n 
 

我尝试完全删除已注释的代码,但仍然没有修复它。

我的文件结构也正确,可以看到 在这里

正如我所说的那样,我对代码点火器仍然很陌生,所以如果答案可以打破巴尼风格,我会很感激。 我也尝试查看一些似乎相关的堆栈溢出问题,但我仍然没有找到有效的解决方案。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqsh30374 2017-12-25 00:55
    已采纳

    You don't have to use the URL helper's functions, but unless you prefix your URLs with a forward slash, the BROWSER decides that your asset is actually prefixed with the URI segments from the current page. That's because the browser sees the URL as a relative URL. In order to overcome that, either use the forward slash, or a base tag: https://www.w3schools.com/tags/tag_base.asp

    Example of base tag:

    <base href="https://example.com/">
    

    In my own applications, I just make my URLs absolute with the forward slash prefix. In your case that would look like this:

    <link href="/assets/css/bootstrap.min.css" rel="stylesheet" />
    

    EDIT ----

    I just noticed that your htaccess has 2 lines, and I'd like you to convert the parens to curly braces, so:

    RewriteCond %(REQUEST_FILENAME) !-f
    

    Should be:

    RewriteCond %{REQUEST_FILENAME} !-f
    

    Just for kicks, try to change this:

    RewriteRule ^ index.php [QSA,L]
    

    To this:

    RewriteRule .* index.php/$0 [PT,L]
    
    点赞 打赏 评论

相关推荐 更多相似问题