Jump to content

.htaccess Question accounting for a folder?


Guest

Recommended Posts

Hi Everyone,

 

How would I go about accounting for a folder in my .htaccess?

 

Meaning this is my domain

 

mydomain.com

 

mydomain.com/products/hot/cakes

 

Should my htaccess code look like this?

RewriteRule ^/products/^([_a-zA-Z]+)/([^/]*)$ script.php?product=$1&inventory=$2 [L]

 

maybe this?

RewriteRule ^/products/([_a-zA-Z]+)/([^/]*)$ script.php?product=$1&inventory=$2 [L]

 

What am asking is this, how would I go about accounting for the actual folder that I want to put in-front of my URL?

 

Thanks

"Accounting for" isn't too descriptive but I think I know what you want.

 

^ applies to the very beginning of the entire URL (sans query string) being matched against. If you try the first one then it'll only match when the beginning of the string is somewhere in the middle of it. Which is impossible. Thus the second one is correct.

 

If you find that the Rule is not matching, try making the leading slash optional. Depending on where these Rules are and what else you may have with them, the slash might not be there.

^/?products/([_a-zA-Z]+)/([^/]*)$

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.