Showing old url in google ....

New to mod_rewrite? This is a good place to start.

Showing old url in google ....

Postby praxs » Mon Jul 20, 2009 7:41 am

Old URL IS
http://www.bni-barnet.co.uk/view_profile.php?bni_id=4

Below is the New URL

http://www.bni-barnet.co.uk/view_profil ... -killoran/

and my HTACCESS FILE

RewriteEngine On
RewriteBase /

RewriteRule ^(.*)$ view_profile.php?bni_id=$1 [QSA,L]

-----------
can you please tell me how should i redirect old url to new url and there are many dynamic id is there ....who should go to the new url...
praxs
 
Posts: 2
Joined: Mon Jul 20, 2009 7:34 am

Postby richardk » Mon Jul 20, 2009 4:38 pm

Do you have access to the httpd.conf file? If you do not, you cannot do that redirect with mod_rewrite because it cannot find/guess the "florist-in-barnet/debbie-killoran" part of the link on it's own. So you will need to do it with PHP instead.

If you do have access to the httpd.conf file you can use a RewriteMap.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby praxs » Mon Jul 20, 2009 11:11 pm

i am using linux shared server ,so i dont have access of php.ini file....could you plz tell me is there any other way , bcoz there are sveral id are there who is showing old page in google ...so i want to redirect to new one...........
praxs
 
Posts: 2
Joined: Mon Jul 20, 2009 7:34 am

Postby richardk » Tue Jul 21, 2009 12:12 pm

i am using linux shared server ,so i dont have access of php.ini file

You don't need access to the php.ini file. You either need access to the httpd.conf file or to use PHP (eg. edit view_profile.php or create a new .php file).

You could have a mod_rewrite such as
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^view_profile/([0-9]+)/[^/]+/[^/]+/?$ /view_profile.php?bni_id=$1 [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?bni_id=[0-9]+(&.*)?$ [NC]
RewriteRule ^view_profile\.php$ /view_profile_redirect.php [QSA,L]

and then in view_profile_redirect.php you would have something like
Code: Select all
<?php

if(isset($_GET['bni_id']) && !empty($_GET['bni_id']))
{
  $user_id = intval($_GET['bni_id']);
  $redirect_url = 'http://' . getenv('HTTP_HOST') . '/view_profile/' . $user_id . '/';

  // Search your database using the user_id variable to get the users information.
  $user_info_1 = ...; // eg. florist-in-barnet
  $user_info_2 = ...; // eg. debbie-killoran

  // Do a 301 redirect.
  header('Location: ' . $redirect_url . $user_info_1 . '/' . $user_info_2 . '/', true, 301);
  exit();
}
else
{
  header('Location: http://' . getenv('HTTP_HOST') . '/', true, 301);
}

There are bits missing in the above. You must make it search your (i presume) database to find the relevant information.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 24 guests

cron