evilscary evilscary - 1 year ago 111
Apache Configuration Question

Adding more directories to url using mod_rewrite

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.

Currently the url before using mod_rewrite looks like:


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

But what I want the URL to look like is:


My htaccess currently looks like:

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

Which results in the URL


How do I add the second level directory?

Answer Source

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]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download