阿帕奇重写规则斜线 [英] Apache rewrite rule leading slash

查看:125
本文介绍了阿帕奇重写规则斜线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

斜线的第一个参数:忽略

是什么

之间的差异语法

 重写规则帮助help.php?Q = noslash [L]#1
重写规则/帮助help.php?Q = withslash [L]#2

如果我打的http://本地主机/帮助,它进入#1,如果我打的 HTTP://本地主机//帮助它仍然往#1

我是说得对的第一个参数重写规则领先斜线基本上忽略了?

斜线第二个参数:误差

此外,为什么没有这个重写规则的工作?

 重写规则帮助/help.php [L]#1

把领先斜线第二arg的面前实际上创建了一个500错误的服务器。为什么呢?

我要说明我使用.htaccess文件写在

这些规则
解决方案

奇怪的是,

 重写规则^ /帮助help.php?Q = 2 [L]

以上规则失败,永远不匹配。

这条规则:

 重写规则^帮助help.php?Q = 1 [L]

://本地主机/帮助,的http://本地主机//帮助的http://本地主机///帮助

这似乎重写规则的从不的路径的斜线开头,并作为TheCoolah说看到<一个href=\"http://stackoverflow.com/questions/4514627/apache-rewrite-rule-leading-slash/4514696#4514696\">they (反正使用.htaccess文件时0 ..)被折叠不管有多少。

有关的问题的第二部分,

 重写规则^帮助/help.php

我收到来自权威指南Apache的mod_rewrite


...重写目标,不以http://或其他协议
指示符被假定为一个文件系统路径。不以斜杠开头的文件路径PTED视为相对于在其中重写正在发生的跨目录$ P $。

所以/help.php看在系统的根一个名为help.php文件,它在我的系统上无法找到。

要做出/help.php显示为相对URL(相对于网站的根),你可以使用[PT]指令:

 重写规则^ /帮助/help.php [PT]

这是指导的http://本地主机/帮助 HTTP:/ /localhost/help.php

Leading slash first argument: ignored?

What's the syntax difference between

RewriteRule help help.php?q=noslash [L]     #1
RewriteRule /help help.php?q=withslash [L]  #2

If I hit http://localhost/help, it goes to #1, if I hit http://localhost//help it still goes to #1.

Am I right in saying the leading slash in the first argument to RewriteRule is essentially ignored?

Leading slash second argument: error?

Also, why doesn't this rewrite rule work?

RewriteRule help /help.php [L]     #1

Putting a leading slash in front of the second arg actually creates a 500 error for the server. Why?

I should note I'm using a .htaccess file to write these rules in

解决方案

Strangely enough,

RewriteRule   ^/help    help.php?q=2              [L]

The above rule fails and never matches.

This rule:

RewriteRule   ^help      help.php?q=1             [L]

Matches http://localhost/help, http://localhost//help and http://localhost///help

It appears RewriteRule never sees leading slashes of the path, and as TheCoolah said they are collapsed (to 0.. when using a .htaccess file anyway) no matter how many there are.

For the second part of the question,

RewriteRule   ^help    /help.php

I'm getting the answer from Definitive Guide to Apache Mod_rewrite

... a rewrite target that does not begin with http:// or another protocol designator is assumed to be a file system path. File paths that do not begin with a slash are interpreted as being relative to the directory in which the rewriting is taking place.

So /help.php looks in the root of the system for a file called help.php, which on my system it cannot find.

To make /help.php appear as a relative URL (relative to the root of the site) you can use the [PT] directive:

RewriteRule   ^/help    /help.php    [PT]

That directs http://localhost/help to http://localhost/help.php.

这篇关于阿帕奇重写规则斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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