Jump to content


Photo

.htaccess Question accounting for a folder?


  • Please log in to reply
1 reply to this topic

#1 scm22ri

scm22ri

    Advanced Member

  • Members
  • PipPipPip
  • 89 posts

Posted 30 January 2013 - 12:09 PM

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

#2 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,125 posts
  • LocationWA

Posted 30 January 2013 - 01:59 PM

"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, 30 January 2013 - 01:59 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com