为什么Apache的重写规则露出本地路径? [英] Why is Apache's RewriteRule revealing local paths?

查看:92
本文介绍了为什么Apache的重写规则露出本地路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的规则集的的.htaccess 相对路径,但是Apache似乎想输出的物理路径,而不是服务器每当我试图输出相对路径路径。绝对和服务器根目录路径,做工精细。例如:

I'm trying to use RewriteRules in .htaccess with relative paths, but Apache seems to want to output the physical path instead of the server path whenever I try to output a relative path. Absolute and server-root paths work fine. For example:

RewriteEngine On

# this works fine, 127.0.0.1/ab redirects to 127.0.0.1/cd
RewriteRule ^ab$ /cd [R]

# this doesn't work... 127.0.0.1/wx redirects to 127.0.0.1/C:/path/to/files/yz
RewriteRule ^wx$ yz [R]

添加一个的RewriteBase / 解决了这个问题,但它是单调乏味的路径添加到每个的.htaccess ,这使得它更难改变目录结构。是否有一个原因的RewriteBase默认为当前的物理路径,而不是当前的 URI 路径?

Adding a "RewriteBase /" solves the problem, but it's tedious to add the path to every .htaccess, and it makes it harder to change the directory structure. Is there a reason RewriteBase defaults to the current physical path instead of the current URI path?

推荐答案

对于那些谁碰巧在这里从谷歌(像我一样)到达时,简短的清单:

For those who happen to arrive here from Google (like me), the short checklist:

  • 请确保您有的RewriteBase / (或任何其他值 - 该语句是什么是重要的)

  • Make sure you have RewriteBase / (or any other value - the statement is what is important)

如果您使用重定向( [R] [R = 30倍] 等) - 确保新的URI开始于一个 / ,其中包含路径相对于你的域名根

If you use redirect ([R], [R=30x], etc) - make sure the new URI starts with a / and contains a path relative to your domain root

(如果上面没有帮助还)重启Apache,清除浏览器的缓存(特别是如果你已经使用 [R = 301] 在某个时候)

(If above didn't help yet) Restart Apache, clear your browser's cache (especially if you have used [R=301] at some point)

这就是我的一天是什么拯救,也许这会节省你的了。

That's what saved my day, maybe it will save yours too.

这篇关于为什么Apache的重写规则露出本地路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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