htaccess:如何重写特定的 GET 变量?

发布于 2025-01-02 21:20:55 字数 623 浏览 2 评论 0原文

对于主菜单,我有大约 3 个标题类别 我喜欢静态重写它们。

这是我现在使用的代码:

RewriteCond %{QUERY_STRING} !dep= [NC]    
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?dep=$1 [NC,L,QSA]   

www.hello.com/car/ 将给出 //$_GET var //?dep=car

简单的我将如何让:www.hello.com /汽车/福特/
let 'return' ?dep=car&id=ford

现在假设我知道我正在使用的 3 个 '?dep' 参数。你怎么能写:

If www.hello.com/? == car || boat || train  /  
rewrite to ?dep=  
else
rewrite to ?id= 

/*
In this example giving www.hello.com/ford/  
would return id=ford     
but, www.hello.com/boat/  
would return dep=boat 
*/

For a main menu I've got about 3 header catagoty's
I like to static rewrite them.

This is the code i'm using now:

RewriteCond %{QUERY_STRING} !dep= [NC]    
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?dep=$1 [NC,L,QSA]   

www.hello.com/car/ will give the //$_GET var //?dep=car

simple how would I let: www.hello.com/car/ford/
let 'return' ?dep=car&id=ford

Now let say I know the 3 '?dep' paramters I'm using. How could you write:

If www.hello.com/? == car || boat || train  /  
rewrite to ?dep=  
else
rewrite to ?id= 

/*
In this example giving www.hello.com/ford/  
would return id=ford     
but, www.hello.com/boat/  
would return dep=boat 
*/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独孤求败 2025-01-09 21:20:55

简单的我会如何让:www.hello.com/car/ford/let 'return' ?dep=car&id=ford

在您的规则之后添加此规则:

RewriteRule ^([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+)/?$ index.php?dep=$1&id=$2 [NC,L,QSA]   

现在假设我知道我正在使用的 3 个“?dep”参数。你怎么写:

你需要改变你的条件,因为你需要检查“id”。然后该规则将专门匹配“汽车”、“船”或“火车”:

RewriteCond %{QUERY_STRING} !(id|dep)= [NC]    
RewriteRule ^(car|boat|train)/?$ index.php?dep=$1 [NC,L,QSA]

并为其余规则添加第二条规则:

RewriteCond %{QUERY_STRING} !(id|dep)= [NC]    
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?id=$1 [NC,L,QSA]

simple how would I let: www.hello.com/car/ford/ let 'return' ?dep=car&id=ford

Add this rule after your rules:

RewriteRule ^([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+)/?$ index.php?dep=$1&id=$2 [NC,L,QSA]   

Now let say I know the 3 '?dep' paramters I'm using. How could you write:

You'll need to change your conditions for this because you need to check for "id". Then the rule would match "car", "boat", or "train" specifically:

RewriteCond %{QUERY_STRING} !(id|dep)= [NC]    
RewriteRule ^(car|boat|train)/?$ index.php?dep=$1 [NC,L,QSA]

And add a second rule for the rest:

RewriteCond %{QUERY_STRING} !(id|dep)= [NC]    
RewriteRule ^([0-9a-zA-Z-]+)/?$ index.php?id=$1 [NC,L,QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文