Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule to a RewriteRule is it possible?

if it is I cant figure it out?

         

bbunlock

9:18 pm on Jul 21, 2007 (gmt 0)

10+ Year Member



Hi and thanks in advance for taking a look at this for me, im thinnking of changing my current url layout to an easier to read, better keyword looking url layout, the way it is cuurently setup is like this (example www.mysite.com/Free-Themes/Nokia/6600/Abstract/1/1/)

now that url above used a RewriteRule but I have changed it to (in htaccess
RewriteRule ^Free\-([0-9a-zA-Z\-_]+)\-([0-9a-zA-Z\-_]+)\-Themes/([0-9a-zA-Z\-_]+)/([0-9]+)/([0-9]+)/$ htaccess_thm_listing.php?m=$1&mod=$2&c=$3&o=$4&pg=$5 [L]) and that works if I type in (www.mysite.com/Free-Nokia-6600-Themes/Abstract/1/1/)

what I want to do is a 301 on the old style url so that the new url looks like this (example www.mysite.com/Free-Nokia-6600-Themes/Abstract/1/1/) but in order to do this I have to create a RewriteRule to redirect to the current RewriteRule (make sence?) and I have been trying for hours with no luck what so ever, I just keep getting intrnal server error (testing on home server before going live on the net)

is this possible? can it be done? below is the last effort I tried to get this to work (and failed of course)

RewriteRule ^Free\-Themes/[0-9a-zA-Z\-_]+)/[0-9a-zA-Z\-_]+)/[0-9a-zA-Z\-_]+)/([0-9]+)/([0-9]+)/$ Free\-$1\-$2\-Themes/$3/$4/$5/$ [R=301,L]

I would be greatfull for any help on this matter

thanks in advance

bbunlock

10:23 pm on Jul 21, 2007 (gmt 0)

10+ Year Member



I was in the middle of replying to this thread with some more info and I cant believe it but my code actualy works (if there isnt a typo in it that is) I was copying and pasting some of the code in again when I noticed that the opening bracket was missing from all my [0-9a-zA-Z\-_]+) code.

I now feel stupid as I have been at this for hours only to now find out that it would have worked no problem if I had actualy typed it in corectly :-(

just wanted to let you know so people didnt spend time on trying to figure out why it didnt work.

I do have one last question though, is the final part of the RewriteRule correct? im reffering to this [R=301,L] I have noticed that there are other options such as N and wanted to know that im using the correct code

thanks in advance

jdMorgan

1:19 am on Jul 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[R=301,L] is fine. You can speed the whole thing up, though, by using the [NC] flag and by removing unnecessary escapes:

RewriteRule ^Free-Themes/[0-9a-z\-_]+)/[0-9a-z\-_]+)/[0-9a-z\-_]+)/([0-9]+)/([0-9]+)/$ Free-$1-$2-Themes/$3/$4/$5/$ [NC,R=301,L]

See the Apache mod_rewrite documentation for the meaning and application of flags -- I can't tell you what you want to do, and so can't tell you how...

Jim

bbunlock

3:14 am on Jul 22, 2007 (gmt 0)

10+ Year Member



jim thanks for the help on that, have changed all code in the htaccess and all working great, I think the most important thing in the code was the NC as I have had loads of 404 errors in my logs where someone has typed a url to my site as (example mysite.com/free-themes/ when the real url is mysite.com/Free-Themes/ and because of the caps F and T in my url it throws a 404, that simple little NC has solved all those problems ;-)

once again thank you for the help

wayne

g1smd

5:59 pm on Jul 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Spotting the answer as you post the question is good!
It means you get to try it out without delay.