Page 1 of 1

url rewrite redirect

Posted: Wed Sep 01, 2010 3:39 pm
by natdrip
hi

I need help with a rewrite rule
it should basically go something like this:

example one:
http://www.erp.com/topic-erp-software ==> http://www.erp.com/articles-a-news/s...text/keywords:erp+software/cat:3/order:rdate.html

example two:
http://www.erp.com/topic-a-b-c-d-etc ==> http://www.erp.com/articles-a-news/s...text/keywords:a-b-c-d-etc/cat:3/order:rdate.html

the user might type in the address bar the short one I want the rewrite rule to take the red word(s) from the short address and put it into the long one


here is the one I have but it doesn't seem to work:

RewriteRule ^(.*)/topic-(^[a-z0-9_-])$ /articles-a-news/search-results_m156/query:all/dir:1/scope:title_introtext_fulltext/keywords:$1/cat:3/order:rdate.html

Thanks
for your help

Re: url rewrite redirect

Posted: Wed Sep 01, 2010 11:09 pm
by requinix
For the first part,

Code: Select all

^/?topic-([a-zA-Z0-9_-]+)$

Re: url rewrite redirect

Posted: Thu Sep 02, 2010 11:35 am
by natdrip
thanks
I made the changes but it is still not working
I think that there is already a rewrite going on and it is scrubbing my rule

Re: url rewrite redirect

Posted: Thu Sep 02, 2010 12:47 pm
by natdrip
ok here is where I am at

if I put the following at the top of the .htaccess page

Code: Select all

RewriteRule ^/?topic-([a-zA-Z0-9_-]+)$ /articles-a-news/search-results_m156/query:all/dir:1/scope:title_introtext_fulltext/keywords:$1/cat:3/order:rdate.html [NC, R=301]  
it works to redirect the page to the destination but I loose the pretty url

if I remove the R=301 i get a 404 no page exists error

how can I make this so I can keep the pretty URL and still go to the correct page?

pretty url:http://www.erp.com/topic-a-b-c-d-etc

Destination: http://www.erp.com/articles-a-news/s... ... rdate.html


Thanks
Nate

Re: url rewrite redirect

Posted: Thu Sep 02, 2010 9:04 pm
by requinix
Add a

Code: Select all

RewriteBase /
before the rule and remove the "/?". (Then remove the R=301.)

Re: url rewrite redirect

Posted: Fri Sep 03, 2010 12:41 am
by natdrip
okay this is what I have

Code: Select all

RewriteBase /
RewriteRule ^topic-([a-zA-Z0-9_-]+)$ /articles-a-news/search-results_m156/query:all/dir:1/scope:title_introtext_fulltext/keywords:$1/cat:3/order:rdate.html [NC,L]  
it is still not working I go to the 404 page error !

Re: url rewrite redirect

Posted: Fri Sep 03, 2010 1:04 am
by natdrip
finally

Got the rr to work :P

solution add a [P]

Code: Select all


RewriteBase /
RewriteRule ^topic-([a-zA-Z0-9_-]+)$ /articles-a-news/search-results_m156/query:all/dir:1/scope:title_introtext_fulltext/keywords:$1/cat:3/order:rdate.html [L,NC,P] 



Re: url rewrite redirect

Posted: Fri Sep 03, 2010 3:31 am
by requinix
If [PT] instead works, use that.

Re: url rewrite redirect

Posted: Fri Sep 03, 2010 12:58 pm
by natdrip
My dilemma just got a little more challenging


the rewrite works! almost

current rule:

Code: Select all

RewriteBase /
RewriteRule ^topic-([a-zA-Z0-9_-]+)$ /articles-a-news/search-results_m156/query:all/dir:1/scope:title_introtext_fulltext/keywords:$1/cat:3/order:rdate.html [L,NC,P] 
the problem is the format of what is passed to ( $1)

it is currently passed as:
green-eggs-and-ham

I need it to passed as:
green+eggs+and+ham

current logic:

Code: Select all

RewriteRule ^topic-([^-/]+(-[^-/]+)*)$ /articles-a-news/search-results_m156/query:all/dir:1/scope:title_introtext_fulltext/keywords:$1/cat:3/order:rdate.html [L,NC,P]