scm22ri Posted January 30, 2013 Share Posted January 30, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/273834-htaccess-question-accounting-for-a-folder/ Share on other sites More sharing options...
requinix Posted January 30, 2013 Share Posted January 30, 2013 (edited) "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 January 30, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/273834-htaccess-question-accounting-for-a-folder/#findComment-1409206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.