| |
| |
|
|
|
|
| |
|
| |
|
| :: |
| Author |
Message |
jshpik1
Joined: 10 Aug 2007 Posts: 6
|
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  |
|
|
| Back to top |
|
 |
|
 |
dcz Administrateur - Site Admin

Joined: 28 Apr 2006 Posts: 13031
|
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 |
|
 |
jshpik1
Joined: 10 Aug 2007 Posts: 6
|
|
| Back to top |
|
 |
SeO Administrateur - Site Admin

Joined: 15 Mar 2006 Posts: 2383
|
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
|
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:
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

Joined: 28 Apr 2006 Posts: 13031
|
Posted: Sun Aug 19, 2007 12:22 pm Post subject: Re: 301 Redirect With PHP http:// to http://www. |
|
|
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 |
|
 |
|
|
| Navigation |
Similar Topics |
|
|
|
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |