Redirecting

Status
Not open for further replies.
#1
Hi, one for Christina probably.

I've just typed this message in notepad, and when I was finished I read it back and realsied I only needed to type the last three lines. So I've copied and pasted them up here for those who don't want to read my rubbish.

What I want;
Is to redirect visitors from a link which has "?typ=" to the same URL but with that changed to "?ps="
Is this possible?


Background:

I had a price comparison site that run on a php script. It developed problems which I couldn't fix, so I changed the script for a different one.

Problem:

The new script has a completely different way of generating pages, and URLs.

If you searched for "DVD+Recorders" with the old script you would go to a URl that ended

it.co.uk/?typ=DVD+Recorders

but do the same on the new site and the URL ends

it.co.uk/?ps=DVD+Recorders

All my entries in search engine pages end in "it.co.uk/?typ=DVD+Recorders" or what ever it was they searched for.
This means that visitors from search engines are not getting to the seach results they hoped for.

I did try to create a 404 shtml page in my cpanel, but I didn't have a clue and ended up just putting a META Refresh in it to the index page.

What I want;

Is to redirect visitors from a link which has "?typ=" to the same URL but with that changed to "?ps="

Is this possible?

Forgot to mention, in Yahoo the URLs have "%3ftyp=" not "?typ=" , so I would like them redirected too.
 
#2
You probably need a 301 redirect which permanently redirects the old urls to the new ones. You can do it through .htaccess files or code it into the php. I recently did it for one of my sites through php and it worked grand. An other option might be to change the variable ps in your new script back to typ it might make more sense if you've only just updated your script.
 
#3
You probably need a 301 redirect which permanently redirects the old urls to the new ones. You can do it through .htaccess files or code it into the php. I recently did it for one of my sites through php and it worked grand. An other option might be to change the variable ps in your new script back to typ it might make more sense if you've only just updated your script.
Thanks, but my knowledge of 301 redirects and .htaccess is zero. Unless someone posts the code for me to copy and paste I am lost.

I do know that changing the php script would be a good option, but my knowledge of php is limited to spotting which line of code "does" something and which line "displays" something.

I don't know anything about the script, apart from it works, so I don't want to go changing things as I may miss something and cause more problems than I solve.

I know you are right, but I need someone to say "copy this and paste it there".
 
#4
*groan*

The .htaccess redirection would be dead easy IFF I actually know how to handle regex - those things called regular expressions which to me are anything but.

But in php I could do it more easily.


I'd want to find the first script that is involved.

Assuming this is index.php, I'd add this at the top of the index.php script, before anything else:

if (isset($_GET['typ'])) {

$http_host = $_SERVER['HTTP_HOST'];
$request_uri = $_SERVER['REQUEST_URI'];
$query_string = $_SERVER['QUERY_STRING'];
$new_request_uri = str_replace("typ=", "ps=", $request_uri);
$new_url = "http://".$http_host.$new_request_uri;

header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: $new_url" );
exit;
}
It should work.

Of course I've not tested it :lol:
 
Last edited:
#5
The .htaccess version will be along the lines of

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)?typ(.*)$
RewriteRule ^(.*)$ %{REQUEST_URI}?ps%2


I think
 
#6
still on redirects

I was reading some stuff on redirects. The popular notion is that redirecting could bring penalties to your site. I remembered I had dozens of redirects because 2 years ago the site markup went from cfm to php. I had a ton of cfm pages in the search engines. I figured the easiest way was to find the top cfm performing pages and then redirect them to the php version. I noticed my PR decreased by 1 some time ago. That loss may or may not be associated with redirects.

I just got finished removing them all. Do you think I will regain any PR like that 1 point I lost? I don't know. If the PR loss was due to redirects, will it come back?
 
#7
Redirections don't bring penalties. Broken navigation doesn't help with indexing. During navigatin of your site robtos shoudl never be exposed to redireciton.

Redirectin should be left to handle old previosuly indexed pages whose names have changed. Of course you must not use the old names in your own navigation.

302 redirection is not to be used across domains.

Tricky javascript redirections and meta refresh redirections might get you penalized, depending on what it is.
 
#8
This is how I did it in my .htaccess

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.domain.com [nc]
rewriterule ^(.*)$ http://domain.com/$1 [r=301,nc]

This redirects the www. domain.com to just plain domain.com. But it should work for other redirects as well ... I hope.

PS: I hate this forum software. It insists that anything with www. is a link and makes it so no matter what I do, :(
 
#9
Well other redirects will have other conditions to test not just the http_host variable.

This is the rub - you need to write regex stuff to do what Joe needs.
 
#10
*groan*

The .htaccess redirection would be dead easy IFF I actually know how to handle regex - those things called regular expressions which to me are anything but.

But in php I could do it more easily.
Thanks Chris, but I couldn't get it to work.

The problem was, without the 404.shtml file I just get a standard "File not found on this server" page. And with the 404.shtml file it redirects just to the index file. So your script never gets the original URL.

However I am convinced it would work, if it was in the 404.shtl file, or I had a 404.php file.

I know there are htaccess suggestions in here, but I tried uploading an htaccess file several times and it just disappears, never reaches the site.
 
#11
Slight change of tack here.

What I would like now is a php and a javascript solution to the following.

PHP solution because I know it works and javascript because I've just spend 1.5 days trying to "adapt" 47 different javascripts to do this and can't get them to work.

What I want is a search box that searches just my site. But it is very simple, just an input box and a button. When the button is pressed the user's browser is redirect to my site with the text from the input box added to the URL.

e.g. The user types "DVD Recorders" into the box and gets sent to www.blahblah.com/?"DVD+Recorders"&blahblah

In other words, take what the user types in, stick in in the middle of a URL and sent the user off to that URL and let the sites own search do the hard work.

The reason I want it is for a custom error page. Instead of just having an error page that says "sorry, page not found. Click here for the main page (or wait 5 seconds"

I want a page that says "The search engine that sent you here is out of date, the information you seek is still on this site but not in the same place. Use the search box and it will find the information you are looking for"

Or word to that effect.

It's got to be better than just sending the to the index page and hoping they find what they are looking for.
 
#14
Redirections don't bring penalties. Broken navigation doesn't help with indexing. During navigatin of your site robtos shoudl never be exposed to redireciton.

Redirectin should be left to handle old previosuly indexed pages whose names have changed. Of course you must not use the old names in your own navigation.

302 redirection is not to be used across domains.

Tricky javascript redirections and meta refresh redirections might get you penalized, depending on what it is.
OK. No penalty. That's great to know. After about a week though many of those pages are now getting placements in results 2 pages higher, like from page 3 to page 1. I did nothing to further optimize the pages I see which were once redirections from cfm to php but they are all performing better in the serps.

Luck of the draw.
 
Status
Not open for further replies.
Top