的.htaccess打破所有的CSS和JS,虽然我设置绝对路径 [英] .htaccess break all css and js, though i set absolute path

查看:109
本文介绍了的.htaccess打破所有的CSS和JS,虽然我设置绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的.htaccess文件

Here is my .htaccess file

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !=cms

RewriteRule ^([^/]*)/search/([^/]+)$  index.php?lang=$1&id=search&searchword=$2 [L]
RewriteRule ^([^/]*)/([^/]*)$  index.php?lang=$1&id=$2 [L]

这是我期待的那样工作。

It doesn't work as i expect.

我的的.css 的.js 文件具有绝对路径,如 HTTP:/ /bs.am/finance/css/style.css (我在融资文件夹中的所有文件)

My .css,.js files has absolute path, like http://bs.am/finance/css/style.css (my all files in finance folder)

第一条规则打破了所有的CSS和JS文件,但如果我更换的规则集的地方,工作正常。

The first rule breaks all css and js files, but if i replace the places of rewriteRules, works fine.

有人能解释这样的行为?

Could somebody explain such behavior?

我也试过的RewriteCond%{} REQUEST_FILENAME!^(。+)\。CSS $ ,但于事无补。

I also tried RewriteCond %{REQUEST_FILENAME} !^(.+)\.css$ but doesn't help.

谢谢了

推荐答案

根据您的问题,看来你的.htaccess文件是在 /财务/ 的文件夹中。如果是这样的话,问题就在于,你的第二个重写规则将匹配您的脚本和sylesheets的要求。

Based on your question, it seems that your .htaccess file is in the /finance/ folder. If this is the case, the problem lies in the fact that your second RewriteRule will match the requests for your scripts and sylesheets.

您已经可以让你避免这个问题的条件,但它们只适用于来后他们(你的搜索规则)的第一个规则。像往常一样,有一些不同的方式来解决的事情,但最简单的就是复制你的的RewriteCond 块,使之适用于第二条规则了。这将如下所示:

The conditions you have already will allow you to avoid this problem, but they only apply to the first rule that comes after them (your search rule). As usual, there are a few different ways to fix things, but the simplest is to copy your RewriteCond block so that it applies to the second rule too. This would look like the following:

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 =cms
RewriteRule ^([^/]*)/search/([^/]+)$  index.php?lang=$1&id=search&searchword=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !=cms
RewriteRule ^([^/]*)/([^/]*)$  index.php?lang=$1&id=$2 [L]

请注意,你可能甚至不需要条件块的第一条规则,因为它可能是不可能的,任何你真正的文件相匹配的测试图案。这是绝对必要的第二个虽然,prevent的资源被误导。

Note that you might not even need the condition block for the first rule, as it's probably unlikely that any of your real files match that test pattern. It is definitely needed on the second one though, to prevent your resources from being misdirected.

另类视角

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond $1 !=cms
RewriteRule ^([^/]*) - [S=2]

RewriteRule ^([^/]*)/search/([^/]+)$  index.php?lang=$1&id=search&searchword=$2 [L]
RewriteRule ^([^/]*)/([^/]*)$  index.php?lang=$1&id=$2 [L]

在此方法中,如果你的任何条​​件下比赛,我们跳过接下来的两个规则(由指定的 S = 2 ,这是相同的适用条件方框他们两人作为<一个href="http://stackoverflow.com/questions/3912412/htaccess-break-all-css-and-js-though-i-set-absolute-path/3922672#3922672">Gumbo提到,你也可以使用标记代替 S = 2 忽略每个规则附带条件中的匹配的情况下,该块后,其中的这些选项是最合适取决于你可能想在将来添加其他什么规则。

In this approach, if any of your conditions match, we skip the next two rules (indicated by the S=2. This is the same as applying the condition block to both of them. As Gumbo mentions, you could also use the L flag in place of the S=2 to ignore every rule that comes after that block in the case of your conditions matching. Which of these options is most appropriate depends on what other rules you might want to add in the future.

这篇关于的.htaccess打破所有的CSS和JS,虽然我设置绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆