htaccess的重写 [英] .htaccess rewriting

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

问题描述

我有这样的.htaccess我一直在使用重写这样的网址是:

I have this .htaccess that I've been using to rewrite URLs like these:

www.example.com/index.php?page=brand          www.example.com/brand
www.example.com/index.php?page=contact        www.example.com/contact
www.example.com/index.php?page=giveaways      www.example.com/giveaways

 

 

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

我使用了一种叫做index.php文件来处理重定向。下面使用code:

I used a file called index.php to handle the redirects. Code used below:

$page = trim($_GET['page']);
if($page == "giveaways")
    require('pages/giveaways.php');

现在,我想补充的另一个URL类型这样的:

Now, I would like to add another URL type like these:

www.example.com/index.php?page=products&p=ford-mustang

www.example.com/products/ford-mustang

我将如何做到这一点?任何建议将大大AP preciated。

How will I accomplish this? Any suggestion would be greatly appreciated.

推荐答案

您需要添加上面您当前的第二重写规则。 这里有一个例子:

You need to add a second RewriteRule above your current one. Here's an example:

RewriteRule ^/(.*)/(.*)$ index.php?page=$1&p=$2 [L,QSA]

这将改写 /产品/福特野马 index.php页面=产品及放大器; P =福特野马

记得添加它上面你目前的重写规则,因为它首先尝试匹配第一个重写规则,当有不匹配,将继续与第二重写规则等进一步。

Remember to add it above your current RewriteRule, because it first tries to match the first RewriteRule, when there's no match it will go on with the second RewriteRule and so further.

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

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