mod_rewrite trouble

This is a discussion on mod_rewrite trouble within the Apache Web Server forums, part of the Web Server and Related Forums category; Hi, I'm trying to mod_rewrite some URLs that follow the same pattern. Old: http://domain.com/test/one/two/...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-14-2007
Mr Marley
 
Posts: n/a
Default mod_rewrite trouble

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?

  #2 (permalink)  
Old 09-14-2007
Jim Hayter
 
Posts: n/a
Default Re: mod_rewrite trouble

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
  #3 (permalink)  
Old 09-14-2007
Mr Marley
 
Posts: n/a
Default Re: mod_rewrite trouble

On Sep 14, 6:02 pm, Jim Hayter <see.reply...@nowhere.invalid> 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.

 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:18 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0