JessicaRod
JessicaRod

Reputation: 1

How to Rewrite a url in a subdirectory and parameters?

Here is the page I'm working with:

www.domain.com/clothing/mens/brand.html?brand=DOPE

I would like to change it to:

www.domain.com/clothing/mens/DOPE

I'm currently using:

RewriteEngine On
RewriteRule  ^mens/brand/([0-9a-zA-Z]+) mens/brand.php?brand=$1 [NC,L]

but that produces the undesired effect:

www.domain.com/clothing/mens/brand/DOPE

when I remove "brand":

RewriteRule  ^mens/([0-9a-zA-Z]+) mens/brand.php?brand=$1 [NC,L]

I don't get an error but a blank page. What am I doing wrong? I have tried everything and nothing seems to work :(

Upvotes: 0

Views: 42

Answers (3)

JessicaRod
JessicaRod

Reputation: 1

I appreciate all that have tried to help, but here is what worked for anyone else looking for an answer.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^mens/([^/]+)$ mens/brand.php?brand=$1 [L]

Upvotes: 0

zessx
zessx

Reputation: 68790

Let do a little recap. You want to have this redirection:

clothing/mens/DOPE   ->   clothing/mens/brand.html?brand=DOPE

But the rule you're using (the first mentioned in your question) will do this:

mens/brand/DOPE      ->   clothing/mens/brand.html?brand=DOPE

I think you should use this rule:

RewriteEngine On
RewriteRule  ^clothing/mens/([\da-z]+) mens/brand.php?brand=$1 [NC,L]

Note that you can simply use [\da-z] (or [0-9a-z]) instead of [0-9a-zA-z], as you're using the No Case [NC] flag.

Upvotes: 0

Than Ngo Hoai
Than Ngo Hoai

Reputation: 469

Try this:

RewriteEngine On
RewriteRule  ^clothing/mens/([0-9a-zA-Z]+) /clothing/mens/brand.html?brand=$1 [NC,L]

The page you are working with is brand.html or brand.php?

Upvotes: 1

Related Questions