帮助关于htaccess中的动态重定向规则 [英] help regarding dynamic redirect rule in htaccess

查看:110
本文介绍了帮助关于htaccess中的动态重定向规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你帮助给定的主题。
我在生活中第一次玩htaccess规则。



这里是场景 -



我想重定向网址 -

  http://www.abc.com/var1 
http:// www.abc.com/var2

到其他网址 -

  http://www.abc.com/index.php?u=var1 
http://www.abc.com/index.php?u = var2

在这种情况下,var1& var2可以是任何东西(即只包含字母数字字符的字符串)。



还有一件事 -



如果网址是 -



http ://www.abc.com/SKIPME



请帮我写这条规则!



Regards,
Shahu!

解决方案

你最好定义一个URI模式,告诉你什么时候会被重写例如...

  http://www.abc.com/site/var1 
http:// www.abc.com/site/var2

这样,你可以确保你只应用规则如果psuedosite /目录被浏览,而不影响任何其他URI。这是基于上述模式的重写规则。

  RewriteEngine on 
RewriteRule ^ site /([^ / \\ \\。] /?$ index.php?u = $ 1 [L,NC,QSA]

除/site/.../之外的任何其他地址都不会受到此规则的影响,这意味着您不必担心设置一些地址被避免。



您不必使用网站 - 您可以使用符合您目的的任何名称。


I need ur help for given subject. I am playing with htaccess rules first time in life.

here is the scene -

i want to redirect the urls -

 http://www.abc.com/var1
 http://www.abc.com/var2

to follwing urls -

 http://www.abc.com/index.php?u=var1
 http://www.abc.com/index.php?u=var2

In this case the values var1 & var2 can be anything (i.e. string which will contain only alphanumeric characters.)

One more thing -

I want to skip this rule if the url is -

http://www.abc.com/SKIPME

Please help me to write this rule!

Regards, Shahu!

解决方案

You would be better off defining a URI schema that tells you when something WILL be rewritten. For example...

 http://www.abc.com/site/var1
 http://www.abc.com/site/var2

That way, you can ensure you only ever apply the rule if the psuedo "site/" directory is browsed and not affect any other URI. This is the rewrite rule based on the above schema.

RewriteEngine on
RewriteRule ^site/([^/\.]+)/?$ index.php?u=$1 [L,NC,QSA]

Any other address, other than "/site/.../" would be unaffected by this rule, which means you don't need to worry about setting some addresses to be avoided. This keeps things as simple as possible.

You don't have to use "site" - you can use whatever name fits your purpose.

这篇关于帮助关于htaccess中的动态重定向规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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