Jason28 Posted December 16, 2013 Share Posted December 16, 2013 I tried different only tools and tutorials about mod_rewrite but I cannot find what I am looking for. I want to rewrite a url like this (I wont include site domain since it is all within the same site directory): /area-1/(random text here)/category-5/(random text here)/ I only want it to find the area number within the slashes /area-ID/ and the category within the slashes /category-ID/ and ignore all of the other text since it changes based on the page title. I tried: RewriteRule ^area-([-0-9]+)/([^/]*)/category-([-0-9]+)\/ test.php?id=$1&var=$2&cat_id=$3 [L] The $var=2 is empty and not needed, but needed to add something there to ignore the stuff in the middle. Please help, I cannot create an account at Stackoverflow because the signup always errors. I contacted their webmaster with no reply. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/284793-cant-get-mod_rewrite-url-to-work-correctly/ Share on other sites More sharing options...
Ch0cu3r Posted December 16, 2013 Share Posted December 16, 2013 Try this rule RewriteRule ^area-([0-9]+)/[^/]+/category-([0-9]+)/ test.php?id=$1&cat_id=$2 [L] The $var=2 is empty and not needed, but needed to add something there to ignore the stuff in the middle. Then don't wrap parentheses around regex that you dont want to reference later on. I cannot create an account at Stackoverflow because the signup always errors. Not relevant Quote Link to comment https://forums.phpfreaks.com/topic/284793-cant-get-mod_rewrite-url-to-work-correctly/#findComment-1462444 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.