NUGGET
NUGGET

Reputation: 61

.htaccess and subdirectories

I am trying to make a .htaccess file that is basically a wildcard setup. I have a folder structure as below.

public_html/sites is the root directory and in this folder there are two sub directories:

public_html/sites/brand (there are many brand folders, just used brand as example)
public_html/sites/brand/event (there are many events in a brand folder, just used event as example)

I have files in each event folder such as index.php and media.php

I have been unsuccessful in rewriting the media page to the URL structure I am looking for. Below is my current .htaccess file.

RewriteEngine On
RewriteRule ^media/([^/]*)$ /media.php?unqid=$1 [L]

So the expected URL I am wanting is /testbrand/4177/media/123456. I will have serveral brands and several events under each brand so I am needing some sort of wildcard if possible. Any help is appreciated. Thanks in advance.

Upvotes: 1

Views: 47

Answers (2)

anubhava
anubhava

Reputation: 786091

You can use this rule in your root .htaccess:

RewriteEngine On

RewriteRule ^([^/]+/[^/]+)/media/(\d+)/?$ $1/media.php?unqid=$2 [L,NC,QSA]

This will load /testbrand/4177/media.php?unqid=123456 when you request /testbrand/4177/media/123456

Upvotes: 0

Panama Jack
Panama Jack

Reputation: 24478

If you are wanting to have a URL like this

http://example.com/testbrand/4177/media/123456

And your brands are dynamic, then your rewrite should probably look something like this.

RewriteRule ^(?:[^/]+)/(?:[0-9]+)/media/([0-9]+)/?$ /media.php?unqid=$1 [L]

Based on your current internal URL you'll only be sending the id number that comes after /media/ to PHP. If you have more info you need to send, then you need to update your internal URI parameters.

Upvotes: 2

Related Questions