301 redirects

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

301 redirects

Postby ultimatehandyman » Tue Dec 15, 2009 3:04 pm

I have a video website that uses phpmotion and I had a friendly url mod installed. The support for the script is not brilliant and it seems only a couple of people can work with the script. The site is on a dedicated server, but I am in the process of uploading all the videos onto youtube, where I will then get the script to embed the videos back on the site.

I am replacing the script with custom made pages and each page will have the relevent youtube video embedded into it.

Here is one of the url's now from the site- http://www.ultimatehandyman.org/videos/ ... opper-pipe

Because there are lots of backlinks linking to some of the pages I thought I could do a 301 redirect through .htaccess but I just tried it and it did not work.

The new page will look like this- http://www.ultimatehandyman.org/compres ... ttings.php (not all links are working yet)

So I need to redirect the old url to the new url.

If anyone can please advise I would appreciate it?

Thanks

chez
ultimatehandyman
PR2
PR2
 
Posts: 250
Joined: Thu Mar 15, 2007 12:55 am

Advertisement

Re: 301 redirects

Postby dcz » Thu Dec 17, 2009 9:47 am

So you'll need a full list of all changes since names did not stayed the same compression-fittings-on-copper-pipe vs compression_fittings.php.

You could use something like :
Code: Select all
<?php
/**
*
* @package Ultimate SEO URL phpBB SEO
*
*/
// Some config
$root_url = 'http://www.example.com/';

$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

$old_uri = !empty($_GET['old_uri']) ? preg_replace('`[^a-z0-9_-]+`i', '', trim($_GET[old_uri'])) : 0;
$url = '';
if ($old_uri) {
   $redirect_map = array(
      //'old_uri' => 'new_uri',
      'compression-fittings-on-copper-pipe' => 'compression_fittings.php',
   );
   if (isset($redirect_map[$old_uri])) {
      $url = $redirect_map[$old_uri];
   }
}
// Will redirect to domain index in case no url was built
$url = $root_url . $url;
header('HTTP/1.1 301 Moved Permanently', false, 301);
header('Location: ' . $url);
exit();
?>

Put this in a file named redirect.php in your domain's root, as you can see, you'll need to enter the full redirect map without taking care of paths :
Code: Select all
   $redirect_map = array(
      //'old_uri' => 'new_uri',
      'compression-fittings-on-copper-pipe' => 'compression_fittings.php',
   );

and to set your root url :
Code: Select all
$root_url = 'http://www.example.com/';


Then, you'll need a rewriterule in your root .htaccess to address old url to that script :
Code: Select all
RewriteRule ^videos/[0-9]+/([a-z-0-9_-]+)$ /redirect.php?old_uri=$1 [QSA,L,NC]


And you'll be done ;)
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Re: 301 redirects

Postby ultimatehandyman » Mon Dec 21, 2009 12:58 pm

Thanks DCZ :wink:

I'll try this in the next few days.

I'll probably be back soon as I am completely clueless about .htaccess etc.

Thanks very much for your help!
ultimatehandyman
PR2
PR2
 
Posts: 250
Joined: Thu Mar 15, 2007 12:55 am

Re: 301 redirects

Postby ultimatehandyman » Sat Dec 26, 2009 9:42 pm

I tried this a couple of days back and I could not get it to work :oops:

At first I added the additional code to the existing .htaccess file and I also added the file called redirect.php and I changed the url root. I could not get it to work, so I deleted the existing .htaccess file and just used the code that you suggested and that did not work.

I have probably done something wrong as I don't have a clue when it comes to .htaccess or redirects.

Any advice would be welcome.

Thanks

chez
ultimatehandyman
PR2
PR2
 
Posts: 250
Joined: Thu Mar 15, 2007 12:55 am

Re: 301 redirects

Postby dcz » Fri Mar 05, 2010 7:27 pm

Sorry for delay.

Is there an .htaccess in videos/ ?

If so, you need to add :
Code: Select all
RewriteRule ^[0-9]+/([a-z-0-9_\.-]+)$ redirect.php?old_uri=$1 [QSA,L,NC]

in it, and put redirect.php in videos/ too.

Otherwise, try some slash combos, such as :
Code: Select all
RewriteRule ^videos/[0-9]+/([a-z-0-9_\.-]+)$ redirect.php?old_uri=$1 [QSA,L,NC]


and make sure you started mod_rewrite before that in your .htaccess and that you have a proper RewriteBase.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Re: 301 redirects

Postby brickpoint » Sun May 02, 2010 3:41 pm

thanks for the advice, i was having similar issues.

thanks :D

http://www.pointingbrickwork.co.uk
brickpoint
 
Posts: 1
Joined: Sun May 02, 2010 3:37 pm


Return to Apache mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 3 guests