有什么问题,通过我的.htaccess重写规则? (为什么它需要的RewriteBase?) [英] What's wrong with my RewriteRule via .htaccess? (Why does it need RewriteBase?)

查看:247
本文介绍了有什么问题,通过我的.htaccess重写规则? (为什么它需要的RewriteBase?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rewriteengine on
rewriterule ^/a/b$ ^/c$

不工作,但

rewriteengine on
rewritebase /
rewriterule ^a/b$ ^c$

的作品。

推荐答案

这也许不一定就是规则的工作这么多,因为领先的斜线的RewriteBase。此外,第二个参数重写规则是不是正规的前pression。相反,尝试:

It's probably not the RewriteBase that makes the rule work so much as the leading slash. Also, the second argument to RewriteRule isn't a regular expression. Instead, try:

RewriteRule ^/?a/b$ c

当应用从一个的.htaccess重写规则,领先的斜线将从URL,这将导致如果包括它的模式失败剥离。通过启动一个模式以^ /?,它会在主配置文件,并在每个目录的配置文件。

When applying a RewriteRule from .htaccess, the leading slash will be stripped from the URL, which will cause the pattern to fail if you include it. By starting a pattern with "^/?", it will work in the main configuration files and in per-directory config files.

详细阅读详细的mod_rewrite文档和的RewriteBase的意义

Read over the detailed mod_rewrite documentation for the details of how the rewrite engine works and the significance of RewriteBase.

编辑: 正如在 mod_rewrite的技术详细信息和的RewriteRule 和的的RewriteBase ,该网址已被翻译为路径的每目录重写规则进行评估的时间。重写引擎不再与工作的URL。相反,它消除了本地目录preFIX(该目录包含.htaccess文件),其中以斜线结束。例如,假设一个用户请求/var/www/foo/bar/baz.html,并有一个重写规则中的/var/www/foo/.htaccess设置。富勒每个规则,重写引擎将去掉/无功/网络/富/,留下酒吧/ baz.html来进行匹配重写规则。处理规则后,本地目录preFIX是prepended(除非更换开始以http://)。毕竟重写规则都已经被处理,重写的基础上,如果设置,替换本地目录preFIX;如果不是,文档根被剥离。重写的URL然后重新注入作为子请求。

As mentioned in the mod_rewrite technical details and described in the documentation for RewriteRule and RewriteBase, the URL has been translated to a path by the time the per-directory rewrite rules are evaluated. The rewrite engine no longer has a URL to work with. Instead, it removes the local directory prefix (the directory holding the .htaccess file), which ends with a slash. For example, suppose a visitor requests "/var/www/foo/bar/baz.html" and there is a rewrite rule set in "/var/www/foo/.htaccess". Fore each rule, the rewrite engine will strip "/var/www/foo/", leaving "bar/baz.html" to be matched against the rewrite rule. After processing a rule, the local directory prefix is prepended (unless the replacement begins with "http://"). After all the rewriting rules have been processed, the rewrite base, if set, replaces the local directory prefix; if not, the document root is stripped. The rewritten URL is then re-injected as a sub-request.

这篇关于有什么问题,通过我的.htaccess重写规则? (为什么它需要的RewriteBase?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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