php redirect
Moderator: General Moderators
php redirect
Hi,
I was wanting to force a page to use www in the url if the www wasn't typed. Does anyone know of a PHP script which does this? And will this make SEO bad?
Cheers,
Doug
I was wanting to force a page to use www in the url if the www wasn't typed. Does anyone know of a PHP script which does this? And will this make SEO bad?
Cheers,
Doug
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: php redirect
PHP redirect...
But yes think it will not be very good for SEO, you should do the redirect in your server setup (config).
Code: Select all
header("LOCATION:index.php");Re: php redirect
As jaoudestudios points out, header redirects trough Location header is bad SEO practice. Instead send the 301 status code response:
Code: Select all
header("HTTP/1.0 301 Moved Permanently");Re: php redirect
Thanks for your responses!
Forgive me for questioning your code, but on first inspection it looks like your code is a redirect without www detection. Would your code only redirect when the www isn't present?
Cheers,
Doug
Forgive me for questioning your code, but on first inspection it looks like your code is a redirect without www detection. Would your code only redirect when the www isn't present?
Cheers,
Doug
Re: php redirect
We did not give you the complete solution, but we did give you the biggest piece of the puzzle.
Here, add this to the beginning of whatever page you want you check in:
Here, add this to the beginning of whatever page you want you check in:
Code: Select all
if(preg_match('#^https?://www\.#i', $_SERVER['REQUEST_URI']) {
header("HTTP/1.0 301 Moved Permanently");
exit();
}Re: php redirect
Hmmm couldn't get it to work. It made my page blank. I put it in a php tag, perhaps I have not implemented it right.
If I goto http://mysite.com, will this code direct me to http://www.mysite.com?
If I goto http://mysite.com, will this code direct me to http://www.mysite.com?
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: php redirect
This might be helpful on url redirect masking...
http://www.forum.jaoudestudios.com/view ... ?f=13&t=86
http://www.forum.jaoudestudios.com/view ... ?f=13&t=86
Re: php redirect
Do you need apache to allow .htaccess files to work?