Jump to content

301 Redirects with PHP


adipalmer123

Recommended Posts

Hi all

 

I created a site a while ago now. Using PHP and MySQL. I set it up using a windows server NOT linux.

I've come to start to do some SEO work on the site, but Google is finding two different urls. the www version and the non www version.

As I'm on a windows server I cant create a htaccess file and add some script to re-direct.

For some reason I dont have IIS installed.

 

I believe you can create a re-direct in PHP. I have done this for the index.php file. It works fine when you go to the homepage but when you click on another link to a different part of the site in Google results, it then redirects me to the homepage. This is obviously messing up my rankings. 

 

The code i used for the re-driect was as follows:

<?php

if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {

header('HTTP/1.1 301 Moved Permanently');

header('Location: http://www.'.$_SERVER['HTTP_HOST']

.$_SERVER['REQUEST_URI']);

}

?>

 

My site works with includes to the index.php file. I thought this would work but obviously not.

 

Anyone any ideas.

 

Adi

Link to comment
Share on other sites

One way to get the htaccess working on a Windows server is by editing your Apache httpd.conf file.

 

AccessFileName .htaccess

 

change to

 

AccessFileName htaccess.txt

 

This allows your server to read htacess.txt as if it was .htaccess.

Link to comment
Share on other sites

You CAN create an HTACCESS file on windows.

 

Run notepad/your fav ascii editor. Fill it with your desired content. File->Save. In the 'Save as Type' dropdown box, choose 'All Files (*.*)'

 

Name the file '.htaccess' (no quotes)

 

???

 

Profit.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.