Adam Posted May 13, 2008 Share Posted May 13, 2008 Hey all... am tryin to use mod rewrite to make some friendly URLs for a site i've been working on for a family friend .. basically the main file to browse is called "Shop.php" ... there's several parameters passed to it and it works on conditionals depending whats been passed, so... if just "c" (which stands for class) is passed obviouslly it just returns the cars with the class of ### .. if "c" and "m" (which stands for model) are passed it will obviouslly return cars with class of ### and model ###.. if "c", "m" and "id" are passed .. OR .. just "id" it will return the car listed under that ID.. so some examples could be: - shop.php?c=SL_Class - shop.php?c=SL_Class&m=R230 - shop.php?c=SL_Class&m=R230&id=C6 - shop.php?id=C6 what i'm struggling to do is create a .htaccess file which will rewrite the files right so i could have: - shop/SL_Class/ - shop/SL_Class/R230/ - shop/SL_Class/R230/C6/ - shop/C6/ I've had a good butchers on the internet but couldn't find any help .. has anyone got a decent tutorial about something similar or any help they could giv me? Thanks a lot, Adam Quote Link to comment https://forums.phpfreaks.com/topic/105353-mod-rewrite/ Share on other sites More sharing options...
Fadion Posted May 13, 2008 Share Posted May 13, 2008 Take a look at this tutorial, its short and consice and goes straight to the point. Im sure it will give u everything u need. Quote Link to comment https://forums.phpfreaks.com/topic/105353-mod-rewrite/#findComment-539579 Share on other sites More sharing options...
Adam Posted May 14, 2008 Author Share Posted May 14, 2008 Cheers for the reply.. I've had a good look round now and I've come up with the following... RewriteEngine on RewriteRule ^browse/([a-zA-Z0-9_]+)/id/([a-zA-Z0-9]+)/?$ index.php?class=$1&id=$2 [L] RewriteRule ^browse/([a-zA-Z0-9_]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9]+)/?$ index.php?class=$1&model=$2&id=$3 [L] RewriteRule ^browse/id/([a-zA-Z0-9]+)/?$ index.php?id=$1 [L] RewriteRule ^browse/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/?$ index.php?class=$1&model=$2 [L] RewriteRule ^browse/([a-zA-Z0-9_]+)/?$ index.php?class=$1 [L] It does work, and quite well.. but is that a long way round to do it? could it be done with just like one regular expression (bare in mind it's not always "class", "model" and "id" in the URL.. "model" and "id" may not be in the URL, sometimes it may just have "class" and "id" in the URL, and also sometimes it may just be "id" in the URL..) so it is quite complicated... any help? cheers! Quote Link to comment https://forums.phpfreaks.com/topic/105353-mod-rewrite/#findComment-540804 Share on other sites More sharing options...
Adam Posted May 15, 2008 Author Share Posted May 15, 2008 Ran into some trouble setting it all up.. it's not displaying css files, javascript files, images and its not linking right.. obivouslly its trying to get say "browse/SL_Class/style.css" is there any way of stopping this? causing big problems on the site.. Cheers! Adam Quote Link to comment https://forums.phpfreaks.com/topic/105353-mod-rewrite/#findComment-542180 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.