使用mod_rewrite将更多目录添加到url [英] Adding more directories to url using mod_rewrite

查看:38
本文介绍了使用mod_rewrite将更多目录添加到url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mod_write从数据库中提取URL.我已经在基本级别上工作了,但是我坚持使用的是使用从数据库中提取的各种标签作为URL中的目录来创建复杂的URL.

I am using mod_write to pull urls out of my database. I have it working at a basic level, but what I am stuck on is creating complex URLs using various slugs pulled from the database as directories in the URL.

当前使用mod_rewrite之前的网址如下:

Currently the url before using mod_rewrite looks like:

www.domainname.co.uk/company?=1&staff=3

在适当样式的公司页面中,您将带您进入工作人员资料.

Which takes you to a staff profile within an appropriately styled company page.

但是我希望URL看起来像是:

But what I want the URL to look like is:

www.domainname.co.uk/COMPANY-NAME/STAFF-NAME

我的htaccess当前如下所示:

My htaccess currently looks like:

RewriteEngine On
RewriteRule ^c/(.*)$ ./company.php?company=$1

URL的结果

www.domainname.co.uk/c/COMPANY-NAME

如何添加二级目录?

推荐答案

您可以为此使用其他规则:

You can use on additional rule for that:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ company.php?company=$1&staff=$2 [L,QSA]

RewriteRule ^c/([\w-]+)/?$ company.php?company=$1 [L,QSA,NC]

这篇关于使用mod_rewrite将更多目录添加到url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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