Forum Moderators: phranque

Message Too Old, No Replies

Redirect via .htaccess to proper url [newbie alert!]

redirect via htaccess

         

phroze

11:43 am on Mar 25, 2007 (gmt 0)

10+ Year Member



Hello,

Since a few hours i've been trying to redirect an invalid query/page to a proper url. No luck at all, not that weird since i'm new to the whole .htaccess thing. Currently the url looks like this:

index.php?section=news&id=215

Instead of that url it should redirect to:
article.php?id=215

The id (215 in this case) is an articleID, so it's not static. Below is what i have so far.

RewriteCond %{QUERY_STRING} ^&id=([0-9]+)
RewriteCond %{QUERY_STRING} ^?section=news
RewriteRule ^index.php$ article.php?id=$1? [R=301,L]

leadegroot

12:14 pm on Mar 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I only ever get .htaccess by trial and error, myself, but I would suggest that you try:

RewriteCond %{QUERY_STRING} ^section=news&id=([0-9]+)
RewriteRule ^index.php$ article.php?id=%1 [R=301,L]

(This is a new approach for me - thanks for getting me to do the research :))

But definitely drop the '?' from the query_string comparision

Hopefully thats a bit closer

phroze

12:29 pm on Mar 25, 2007 (gmt 0)

10+ Year Member



Thanks for the help leadegroot! It worked perfectly. Only had to add a slash in front of the article.php cause somehow it redirected to the root of my webserver :)

I think I'm gonna mess around with htaccess for a while to learn more about it. Thanks!

leadegroot

12:51 pm on Mar 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh good! :)
You're welcome!