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/...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
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 |
|
|||
|
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 | |
|
|