的.htaccess:检查查询字符串具有一定的价值,否则重定向 [英] .htaccess: Check if query string has a certain value or else redirect it

查看:111
本文介绍了的.htaccess:检查查询字符串具有一定的价值,否则重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解一些的.htaccess和我对什么可以做的非常着急。我看见一个片段在网上,但不能让它开始工作,它基本上是这样的如果查询字符串不具有一定的价值,重定向到的index.php 代替或其他页面。我该怎么办呢?

这将查找值的苹果的:

  www.domain.com/somefile.php?a=apples&b=xyz
 

这将重定向到index.php,而不是:

  www.domain.com/somefile.php?a=stinkycheese&b=xyz
 

解决方案

您需要使用%{QUERY_STRING}变量的RewriteCond内。因此,举例来说,如果你不想重定向,如果存在一个重定向=没有在查询字符串,它是这样的:

 的RewriteCond%{QUERY_STRING}(^ |&安培;)重定向=无($ |&安培;)
重写规则。的index.php [L]
 

因此​​,如果的RewriteCond失败(它有一个重定向=没有的查询字符串),那么不适用下列规则,重写任何请求URI是的index.php 。你所需要的实际规则可能会有所不同,但使用的RewriteCond和%{QUERY_STRING}是您要的基本思路。

I'm trying to learn a bit of .htaccess and am really anxious on what it can do. I saw a snippet online but can't get it to work, it basically goes like this If a query string does not have a certain value, redirect it to index.php instead or some other page. How do I do that?

This looks for the value apples:

www.domain.com/somefile.php?a=apples&b=xyz

This will redirect to index.php instead:

www.domain.com/somefile.php?a=stinkycheese&b=xyz

解决方案

You need to use the %{QUERY_STRING} variable inside a RewriteCond. So for example, if you don't want to redirect if there exists a redirect=no in the query string, it would look like this:

RewriteCond %{QUERY_STRING} !(^|&)redirect=no($|&)
RewriteRule . /index.php [L]

So if the RewriteCond fails (it has a redirect=no in the query string), then do not apply the following rule, which rewrites whatever the request URI is to /index.php. The actual rule that you need may be different, but using RewriteCond and %{QUERY_STRING} is the basic idea that you want.

这篇关于的.htaccess:检查查询字符串具有一定的价值,否则重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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