限制在apache的重定向某些URL模式 [英] Restrict some url pattern in a apache redirect

查看:200
本文介绍了限制在apache的重定向某些URL模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个重定向到匹配的淅沥/消息的任何URL / *在这里。

I am writing a redirect to match any url of the patter /message/* here.

RewriteRule ^/message/(.+)$ http://abet.in/message/$1 [NC,R=301,L]

现在我想通过禁止在一些URL字符串模式进行修改。

RewriteCond to check /message/index.html in the url. 

1. Check if the request url contains /message/index.html.
2. If the condition is not met then do a redirect.

我尝试以下方法。但我不知道他们是否是正确与否。

I tried the following methods. But I am not sure whether they are correct or not.

RewriteCond %{THE_REQUEST} !^/message/index

RewriteCond %{REQUEST_URI} !^/message/index [NC]

能否有人告诉如何做到这一点。

Could some one tell how to do this.

推荐答案

%{THE_REQUEST} 包含一个字符串,看起来像这样为一个普通页面请求:

%{THE_REQUEST} contains a string that looks like this for a regular page request:

GET /message/index.html HTTP/1.1

%{REQUEST_URI} 是这样的:

/message/index.html

所以,你的第二个选项是正确的差不多。你并不需要一个 / 模式的开始的的规则集。

此外,这两个规则将prevent启动的所有请求 /消息/指数被重定向):

Additionally, these two rules will prevent all requests that start /message/index from being redirected):

RewriteCond %{REQUEST_URI} !^/message/index [NC]
RewriteRule ^message/(.+)$ http://abet.in/message/$1 [NC,R=301,L]

如果您只想prevent /message/index.html ,而不是 /message/index.php /消息/指数的出头,其他然后执行:

If you only want to prevent /message/index.html and not /message/index.php or /message/index-of-something-else then do:

RewriteCond %{REQUEST_URI} !^/message/index\.html [NC]
RewriteRule ^message/(.+)$ http://abet.in/message/$1 [NC,R=301,L]

这篇关于限制在apache的重定向某些URL模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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