|
Home > Archive > Apache Server configuration support > September 2007 > mod_rewrite trouble
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
mod_rewrite trouble
|
|
| Mr Marley 2007-09-14, 1:24 pm |
| 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?
| |
| Jim Hayter 2007-09-14, 1:24 pm |
| 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
| |
| Mr Marley 2007-09-14, 7:23 pm |
| On Sep 14, 6:02 pm, Jim Hayter <see.reply...@nowhere.invalid> wrote:
> Mr Marley wrote:
>
>
>
>
>
>
>
> 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.
|
|
|
|
|