url rewrite redirect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
natdrip
Forum Newbie
Posts: 7
Joined: Tue Aug 31, 2010 4:51 pm

url rewrite redirect

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: url rewrite redirect

Post by requinix »

For the first part,

Code: Select all

^/?topic-([a-zA-Z0-9_-]+)$
natdrip
Forum Newbie
Posts: 7
Joined: Tue Aug 31, 2010 4:51 pm

Re: url rewrite redirect

Post 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
natdrip
Forum Newbie
Posts: 7
Joined: Tue Aug 31, 2010 4:51 pm

Re: url rewrite redirect

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: url rewrite redirect

Post by requinix »

Add a

Code: Select all

RewriteBase /
before the rule and remove the "/?". (Then remove the R=301.)
natdrip
Forum Newbie
Posts: 7
Joined: Tue Aug 31, 2010 4:51 pm

Re: url rewrite redirect

Post 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 !
natdrip
Forum Newbie
Posts: 7
Joined: Tue Aug 31, 2010 4:51 pm

Re: url rewrite redirect

Post 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] 


User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: url rewrite redirect

Post by requinix »

If [PT] instead works, use that.
natdrip
Forum Newbie
Posts: 7
Joined: Tue Aug 31, 2010 4:51 pm

Re: url rewrite redirect

Post 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] 
Post Reply