简体   繁体   English

codeigniter .htaccess 文件无法访问 css 和 js 文件后添加用户代理过滤器给出 404

[英]codeigniter .htaccess file unable access css and js file after addition of useragent filter giving 404

codeigniter .htaccess file unable access css and js file after addition of useragent filter giving 404 codeigniter .htaccess 文件无法访问 css 和 js 文件后添加用户代理过滤器给出 404

 RewriteEngine On
 RewriteCond %{HTTP_USER_AGENT} AltaVista [OR]
 RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
 RewriteRule .? - [S=1]
 RewriteCond %{REQUEST_FILENAME} !-f   
 RewriteCond %{REQUEST_FILENAME} !-d 
 RewriteRule .? - [S=0]
 RewriteCond %{REQUEST_FILENAME} -f   
 RewriteCond %{REQUEST_FILENAME} -d   
 RewriteRule .? - [S=2]
 RewriteRule ^(.*)$ index.php?/$1 
 RewriteRule ^(.*)$ /error_page.php 
 # 1 RewriteCond %{HTTP_USER_AGENT} AltaVista [OR] RewriteCond %{HTTP_USER_AGENT} Googlebot [OR] RewriteRule.? - [S=1] # 2 RewriteCond %{REQUEST_FILENAME}.-f RewriteCond %{REQUEST_FILENAME}?-d RewriteRule.? - [S=0] # 3 RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} -d RewriteRule .? - [S=2]

It's unclear which directives you've "added" since #1 and #2 are nonsense and aren't actually doing anything.不清楚您“添加”了哪些指令,因为 #1 和 #2 是无稽之谈,实际上并没有做任何事情。 The erroneous OR flag on the last RewriteCond directive of the first rule results in the rule always being successful and skipping the next rule, which isn't actually doing anything anyway.第一条规则的最后一个RewriteCond指令上的错误OR标志会导致规则始终成功并跳过下一条规则,这实际上并没有做任何事情。

So, you could (and probably should) remove #1 and #2 and you will see no change.因此,您可以(并且可能应该)删除 #1 和 #2 并且您不会看到任何变化。

The problem with being "unable to access css and js files" is caused by rule #3 (but this isn't associated with a "user-agent filter"). “无法访问 css 和 js 文件”的问题是由规则 #3 引起的(但这与“用户代理过滤器”无关)。 This is checking if the request maps to a file AND a directory, which is impossible so is never processed and the following two rules are not skipped ( S=2 ).这是检查请求是否映射到文件和目录,这是不可能的,因此永远不会被处理,并且不会跳过以下两个规则( S=2 )。 This means that requests for any static resources (such as CSS and JS files) are passed to the Codeigniter front-controller, rather than "skipping it", which presumably results in a 404 (because they are not valid CI routes). This means that requests for any static resources (such as CSS and JS files) are passed to the Codeigniter front-controller, rather than "skipping it", which presumably results in a 404 (because they are not valid CI routes).

You need an OR flag on the first condition.您需要在第一个条件上使用OR标志。 For example:例如:

# 3
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d   
RewriteRule .? - [S=2]

However, there are still more problems...然而,还有更多的问题......

 RewriteRule ^(.*)$ index.php?/$1 RewriteRule ^(.*)$ /error_page.php

The first rule that rewrites to the CI front-controller ( index.php ) needs an L (or END ) flag.重写 CI 前端控制器( index.php )的第一条规则需要一个L (或END )标志。

And the second rule (that rewrites everything to /error_page.php ) does not make sense in this context and should be removed.第二条规则(将所有内容重写为/error_page.php )在这种情况下没有意义,应该被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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