mod_rewrite trouble

mod_rewrite trouble

am 14.09.2007 18:41:12 von Mr Marley

Hi,

I'm trying to mod_rewrite some URLs that follow the same pattern.

Old: http://domain.com/test/one/two/cat/id/title/
New: http://domain.com/test/cat/title/

So basically carrying over /cat/ and /title/ but stripping out /one/, /
two/ and /id/.

This is what I have but it isn't working.. (404).

RewriteEngine On
RewriteBase /test/
RewriteRule ^one/two/([0-9a-zA-Z]+)/([0-9]+)/([0-9a-zA-Z]+)$
http://domain.com/test/$1/$3 [R=301,L]

Could be I've made an obvious mistake. Any ideas?

Re: mod_rewrite trouble

am 14.09.2007 19:02:55 von Jim Hayter

Mr Marley wrote:
> Hi,
>
> I'm trying to mod_rewrite some URLs that follow the same pattern.
>
> Old: http://domain.com/test/one/two/cat/id/title/
> New: http://domain.com/test/cat/title/
>
> So basically carrying over /cat/ and /title/ but stripping out /one/, /
> two/ and /id/.
>
> This is what I have but it isn't working.. (404).
>
> RewriteEngine On
> RewriteBase /test/
> RewriteRule ^one/two/([0-9a-zA-Z]+)/([0-9]+)/([0-9a-zA-Z]+)$
> http://domain.com/test/$1/$3 [R=301,L]
>
> Could be I've made an obvious mistake. Any ideas?
>

Why are you trying to match the "id" with [0-9]+? Is this actually a
number? Also, you don't need the parentheses around it unless you want
to access it as $2.
Also, you may need to deal with the terminal /. Try this:

RewriteRule ^one/two/([0-9a-zA-Z]+)/[0-9a-zA-Z]+/([0-9a-zA-Z]+)/?$
http://domain.com/test/$1/$2 [R=301,L]

Jim

Re: mod_rewrite trouble

am 14.09.2007 20:31:18 von Mr Marley

On Sep 14, 6:02 pm, Jim Hayter wrote:
> Mr Marley wrote:
> > Hi,
>
> > I'm trying to mod_rewrite some URLs that follow the same pattern.
>
> > Old:http://domain.com/test/one/two/cat/id/title/
> > New:http://domain.com/test/cat/title/
>
> > So basically carrying over /cat/ and /title/ but stripping out /one/, /
> > two/ and /id/.
>
> > This is what I have but it isn't working.. (404).
>
> > RewriteEngine On
> > RewriteBase /test/
> > RewriteRule ^one/two/([0-9a-zA-Z]+)/([0-9]+)/([0-9a-zA-Z]+)$
> >http://domain.com/test/$1/$3[R=301,L]
>
> > Could be I've made an obvious mistake. Any ideas?
>
> Why are you trying to match the "id" with [0-9]+? Is this actually a
> number? Also, you don't need the parentheses around it unless you want
> to access it as $2.
> Also, you may need to deal with the terminal /. Try this:
>
> RewriteRule ^one/two/([0-9a-zA-Z]+)/[0-9a-zA-Z]+/([0-9a-zA-Z]+)/?$http:/ /domain.com/test/$1/$2[R=301,L]
>
> Jim

Thanks Jim, you were right about not needing the parentheses around
the id. Also about the terminal /, I've now got that covered. Learnt a
lot today.

Got there in the end, I still had a few problems such as forgetting
the title would always has a hyphen!

I'm having to use .htaccess for this site and I think that means you
can't use the log, which makes debugging very hard.