简体   繁体   English

使用mod_rewrite将更多目录添加到url

[英]Adding more directories to url using mod_rewrite

I am using mod_write to pull urls out of my database. 我正在使用mod_write从数据库中提取URL。 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. 我已经在基本级别上工作了,但是我坚持使用的是使用从数据库中提取的各种标签作为URL中的目录来创建复杂的URL。

Currently the url before using mod_rewrite looks like: 目前,使用mod_rewrite之前的网址如下:

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

Which takes you to a staff profile within an appropriately styled company page. 在适当的样式的公司页面中,您可以进入员工资料。

But what I want the URL to look like is: 但是我希望URL看起来像是:

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

My htaccess currently looks like: 我的htaccess当前看起来像:

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

Which results in the URL 产生网址

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

How do I add the second level directory? 如何添加二级目录?

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]
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9_-\.]+)/([a-zA-Z0-9_-\.]+)(/?)$ /company.php?company=$1&staff=$2 [NC,L]


That should allow urls of the type:
www.domainname.co.uk/COMPANY-NAME/STAFF-NAME

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM