phpBB SEO
Boards
Directory  
SEO  
Downloads
  phpBB SEO : Search Engine Optimization, Directory, Forums  
Index
Forums
Annuaire
Référencement
Télécharger
 
  Search Rechercher
    Register
Username :  Password :  Log me on automatically each visit  
S'enregistrer  
 
   
301 Redirect With PHP http:// to http://www.

 
Post new topic   Reply to topic    phpBB SEO » SEO Forum  » phpBB SEO TooLKit  » Zero duplicate
::  
Author Message
jshpik1



Joined: 10 Aug 2007
Posts: 6

301 Redirect With PHP http:// to http://www.Posted: Wed Aug 15, 2007 12:47 pm    Post subject: 301 Redirect With PHP http:// to http://www.

Hello,

I'm trying to do a 301 redirect all non www. to all www.domainname.com pages, should probably be included in the page_header.php file... Here's what I have:

Quote:

# <?php
# if(!stristr($_SERVER["HTTP_HOST"], 'www')){
# header("HTTP/1.1 301 Moved Permanently");
# header("Location: http://www.domainname.com/" . $_SERVER["REQUEST_URI"]);
# exit();
# }
# ?>


The only problem is redirects all pages it's on as 301's to the listed domain. How do I make this so it redirects the page it's on if it's http:// to http://www. using 301? The problem is my hosting provider does not allow me to do this with htaccess. This might also be something that you may want to include in a future version of this Laughing
Back to top
dcz
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 13031

301 Redirect With PHP http:// to http://www.Posted: Thu Aug 16, 2007 8:30 am    Post subject: Re: 301 Redirect With PHP http:// to http://www.

The phpBB3 zero duplicate is actually checking the full URL, including the domain, so it's making sure about the prefix already, and does not even require the mod rewrite to work.

So with phpBB2, this code should work:

Code:
if(strpos($_SERVER['HTTP_HOST'], 'www.') === FALSE){
     header("HTTP/1.1 301 Moved Permanently", FALSE, 301);
     header("Location: http://www.domainname.com/" . ltrim($_SERVER['REQUEST_URI'], '/') );
     exit;
}


++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
jshpik1



Joined: 10 Aug 2007
Posts: 6

301 Redirect With PHP http:// to http://www.Posted: Thu Aug 16, 2007 10:39 am    Post subject: Re: 301 Redirect With PHP http:// to http://www.

That's wierd then because things like http://www.domainname.com/viewtopic.php?t=36 redirect as a 301 to the mod rewrite version properly, but things like http://domainname.com/viewtopic.php?t=36 redirects with a 302 to http://www.domainname.com/viewtopic.php?t=36 which then directs with a 301 to the mod rewrite link.

If I place that code in page_header.php it redirects all pages with a 301 to http://www.domainname.com/ (including http://www.domainname.com/) which would get me removed from search engines in a hurry, and it also causes an infinite loop because http://www.domainname.com/ keeps redirecting to http://www.domainname.com/.

Thanks.
Back to top
SeO
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 15 Mar 2006
Posts: 2383

301 Redirect With PHP http:// to http://www.Posted: Thu Aug 16, 2007 11:02 am    Post subject: Re: 301 Redirect With PHP http:// to http://www.

jshpik1 wrote:
the mod rewrite link


I thought you could not use .htaccess ?

_________________
Back to top
jshpik1



Joined: 10 Aug 2007
Posts: 6

301 Redirect With PHP http:// to http://www.Posted: Fri Aug 17, 2007 4:15 am    Post subject: Re: 301 Redirect With PHP http:// to http://www.

I can't do redirects with htaccess like the commands:

Quote:

# Redirect
# RedirectMatch
# RedirectPermanent
# RedirectTemporary


So I'm assuming I can't do things like:

Quote:

# RewriteCond %{HTTP_HOST} ^domainname.com [NC]
# RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]


I've tried it and it doesn't work. I think the hosting provider has http:// automatically redirect to the www. version with 302. I can do mod rewrites though.
Back to top
dcz
Administrateur - Site Admin
Administrateur - Site Admin


Joined: 28 Apr 2006
Posts: 13031

301 Redirect With PHP http:// to http://www.Posted: Sun Aug 19, 2007 12:22 pm    Post subject: Re: 301 Redirect With PHP http:// to http://www.

jshpik1 wrote:
That's weird then because things like http://www.domainname.com/viewtopic.php?t=36 redirect as a 301 to the mod rewrite version properly, but things like http://domainname.com/viewtopic.php?t=36 redirects with a 302 to http://www.domainname.com/viewtopic.php?t=36 which then directs with a 301 to the mod rewrite link.


Did you install the zero duplicate mod ?

I cannot really get how you could have rewritten links if you cannot use mod_rewrite.

About the 302 header, you could try :
Code:
if(strpos($_SERVER['HTTP_HOST'], 'www.') === FALSE){
     header("HTTP/1.1 301 Moved Permanently", TRUE, 301);
     header("Location: http://www.domainname.com/" . ltrim($_SERVER['REQUEST_URI'], '/') );
     exit;
}


++

_________________
Useful links :
SEO Forum || SEO Directory || SEO phpBB || SEO phpBB3 || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Référencement phpBB3 || Recherche
Back to top
Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    phpBB SEO » SEO Forum  » phpBB SEO TooLKit  » Zero duplicate
Page 1 of 1

Navigation Similar Topics

Jump to: