Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/105353-mod-rewrite/
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/105353-mod-rewrite/#findComment-540804
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/105353-mod-rewrite/#findComment-542180
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.