在根目录下的.htaccess mod_rewrite的,但需要它来跳过所有其他目录 [英] .htaccess mod_rewrite on root directory but need it to skip all other directories
问题描述
下面是目录提纲:
/
/css
/js
/admin
/config
/etc...
所以,这就是我想:
So this is what I would like:
/ <-- Mod re-write for this directory only, skip the rest
/css
/js
/admin
/config
/etc...
.htaccess文件:
.htaccess file:
# Turn rewrite engine on
RewriteEngine On
# Set the base path
RewriteBase /
# now the rewriting rules
RewriteRule ^([0-9A-Za-z]+)/?$ /query.php?id=$1 [L]
想跳过所有目录以外的根目录下,我该怎么办呢?
Would like to skip all directories except the root directory, how do I do this?
推荐答案
另一种解决方案:将这些规则之一,您的规则面前:
Another solution: Put one of these rules in front of your rules:
RewriteRule ^(css|js|admin|config|…)(/|$) - [L]
RewriteCond %{DOCUMENT_ROOT}$0 -d
RewriteRule ^[^/]+ - [L]
最后命名的规则将适用于任何现有的目录,但只如果放在.htaccess文件在服务器上的文档根目录。否则,你就需要调整的RewriteCond
EX pression %{DOCUMENT_ROOT} $ 1,0
的具体路径,例如: %{DOCUMENT_ROOT}富/酒吧/ $ 1,0
。
The last named rule will work for any existing directory but only if placed in the .htaccess file in the document root of the server. Otherwise you will need to adjust the RewriteCond
expression %{DOCUMENT_ROOT}$0
with the specific path, e.g. %{DOCUMENT_ROOT}foo/bar/$0
.
这篇关于在根目录下的.htaccess mod_rewrite的,但需要它来跳过所有其他目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!