Jump to content

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]+)/([^/]*)$

Edited by requinix
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.