This is my htaccess:
这是我的htaccess:
RewriteEngine On
# Stop if it's a request to an existing file.
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
# Redirect all requests to the index page
RewriteRule ^([^/]) /index.php [L]
Now this forwards everything to my index.php script! It dosen't stop if a script exists. Anyone have any idea why this isn't working? I've looked everywhere, but I don't really understand mod_rewrite (as much as I thought!).
现在,这会将所有内容转发到我的index.php脚本!如果脚本存在,它不会停止。任何人都知道为什么这不起作用?我到处寻找,但我真的不懂mod_rewrite(就像我想的那样!)。
The problem has come about because I've put in <script>
tags which point to .js files in my web directory which are then forwarded to the index.php script. The web developer toolbar tells me this. :) And clicking links to the js files in firefox's view source window also shows the index.php output.
问题出现了,因为我已经放入了
thank you.
谢谢。
2 个解决方案
#1
8
This is because after processing a rewrite rule the whole process restarts with the new url. The processing of an url can go thru the rules over and over again each time with the changed URL, until there is no more change (no applying rules found).
这是因为在处理重写规则之后,整个过程将使用新的url重新启动。每次使用更改的URL,URL的处理可以一遍又一遍地通过规则,直到不再有更改(没有找到应用规则)。
You need this:
你需要这个:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php [L]
Don't think of the rules as a program, they are rules which can overlap and must be as specific as possible with each one.
不要将规则视为一个程序,它们是可以重叠的规则,并且必须尽可能具体。
#2
1
I guess you should add [OR] after the first condition like this:
我想你应该在第一个条件之后添加[OR],如下所示:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.*) $1 [QSA,L]
#1
8
This is because after processing a rewrite rule the whole process restarts with the new url. The processing of an url can go thru the rules over and over again each time with the changed URL, until there is no more change (no applying rules found).
这是因为在处理重写规则之后,整个过程将使用新的url重新启动。每次使用更改的URL,URL的处理可以一遍又一遍地通过规则,直到不再有更改(没有找到应用规则)。
You need this:
你需要这个:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php [L]
Don't think of the rules as a program, they are rules which can overlap and must be as specific as possible with each one.
不要将规则视为一个程序,它们是可以重叠的规则,并且必须尽可能具体。
#2
1
I guess you should add [OR] after the first condition like this:
我想你应该在第一个条件之后添加[OR],如下所示:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (.*) $1 [QSA,L]