rewrite request

Discuss practical ways rearrange URLs using mod_rewrite.

rewrite request

Postby modano » Tue Apr 14, 2009 7:44 am

Hello,

I have now tried to figure out htaccess but it is just too confusing for me and I dont get anything to work the way i want, so hopefully someone here can help me.

I would like a url such as this:
domain.com/shoes/10/red/

map to:
domain.com/shoes/index.php?size=10&color=red

And /shoes/ is an actual folder, where I will be pulling the index file from and also images.

There would be more products than 'shoes' so I dont want to have to enter the word 'shoes' into my htaccess, it would a lot of lines.

Is this possible?

regards,
Dan
modano
 
Posts: 5
Joined: Tue Apr 14, 2009 7:06 am

Postby richardk » Wed Apr 15, 2009 9:12 am

If there are different products, will it always be size and color?
Will there always be size and color?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/$1/-d
RewriteRule ^([^/]+)/([0-9]+)/([^/]+)/?$ /$1/index.php?size=$1&color=$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby modano » Thu Apr 16, 2009 7:06 am

thank you for your reply Richard,
and yes, there will always be a size and color.

i tried the code u gave me, but unfortunately it gave this back:
"Internal Server Error"

Im not sure what is wrong but i see $1 used in two places, is that the problem?

thank you for your time.
modano
 
Posts: 5
Joined: Tue Apr 14, 2009 7:06 am

Postby richardk » Thu Apr 16, 2009 8:38 am

i tried the code u gave me, but unfortunately it gave this back:
"Internal Server Error"

What does you error log say is causing the error?
Try removing the Options line.

Im not sure what is wrong but i see $1 used in two places, is that the problem?

It is an error, but it is not the problem causing the 500 error.
Code: Select all
/$1/index.php?size=$2&color=$3
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby modano » Fri Apr 17, 2009 5:17 am

thank you for your reply Richard,
I tried removing the options line but still gives errors.
Just checked the logfile and this is what it says:
.htaccess: RewriteCond: bad argument line '%{DOCUMENT_ROOT}/$1/-d'

regards,
modano
modano
 
Posts: 5
Joined: Tue Apr 14, 2009 7:06 am

Postby modano » Fri Apr 17, 2009 5:25 am

Hi again Richard,

I got it to work, it was a missing space before the '-d' part of this line:
RewriteCond %{DOCUMENT_ROOT}/$1/-d

One problem though, it seem to only work when both the color and size variables are present (or none).
This one works perfectly:
domain.com/shoes/10/red/

while this one does not work:
domain.com/shoes/10/

*edit*
and thats a * instead of the +. all working great, thanks for your help Richard!

regards,
modano
modano
 
Posts: 5
Joined: Tue Apr 14, 2009 7:06 am

Postby richardk » Fri Apr 17, 2009 8:31 am

Use
Code: Select all
^([^/]+)(?:/([0-9]+)(?:/([^/]+))?)?/?$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby modano » Fri Apr 17, 2009 2:27 pm

works even better, thanks a bunch Richard!
modano
 
Posts: 5
Joined: Tue Apr 14, 2009 7:06 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 27 guests

cron