Reputation: 65
I have URLs in this format
site.com/brochure/12/subcat/subcat/maincat
The only important part of the string to my application is the number directly after brochure
There can sometimes be many subcat
false directories so I've had to use many rules like these to make it work
RewriteRule ^brochure/([^/]+)/([^/]+)/([^/]+)/?$ brochure.php?cat_path=$1
RewriteRule ^brochure/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ brochure.php?cat_path=$1
RewriteRule ^brochure/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ brochure.php?cat_path=$1
etc etc - sometimes up to five different rules to allow for the different directory structures.
I'm guessing this can be done in a single rule, anyone kind enough to share their ideas?
Thanks
Upvotes: 1
Views: 43
Reputation: 3596
Since you don't care about any part of the string after your initial ([^/]+)
, why not just use something like:
RewriteRule ^brochure/([^/]+).*$ brochure.php?cat_path=$1
This will match and group your 12
, then quietly match and discard the remainder of the string (.*$
).
Upvotes: 3