Jump to content

Redirecting Query strings


defeated

Recommended Posts

I noticed that one of my pages is incorrectly indexed by google.... presumably I added a link badly somewhere.

 

The problem page request

mypage.php?page=

As you can see there is no value for the page variable.

 

It should read

mypage.php?page=contact

 

If I try to redirect like so...

RewriteRule ^mypage.php?page= mypage.php?page=contact

It ends up in a loop.  That makes sense but I can't figure out how to do it.  Any resident geniuses able to help me out here?

 

Unfortunately the incorrect version is the one that google has indexed which has resulted in the page title showing up as the default " Uh oh, somethings wrong around here

". Shame because it's at number one in google for a specific search term.  I have blocked in in my robots.txt and added it for removal but it would be nicer to have a redirect.

Link to comment
Share on other sites

You can use php to redirect it if the page is invalid like this :

 

$validpage = array('home', 'info', 'contact');
if (!(in_array($_GET['page'], $validpage)))
{
  header("HTTP/1.0 301 Moved Permanently");
  header('Location: http://www.example.com/');
  die();
}

 

Which is a good security pratice too preventing any bad input (like SQL Injection).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.