adipalmer123 Posted May 5, 2011 Share Posted May 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235623-301-redirects-with-php/ Share on other sites More sharing options...
dragon_sa Posted May 5, 2011 Share Posted May 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235623-301-redirects-with-php/#findComment-1211031 Share on other sites More sharing options...
adipalmer123 Posted May 5, 2011 Author Share Posted May 5, 2011 So if I just add a htaccess.txt file to my root directory with all the rewrite info in there, it will work? I dont use a local host you see, I upload directly to a test site. Really appriciate your help Adi Quote Link to comment https://forums.phpfreaks.com/topic/235623-301-redirects-with-php/#findComment-1211109 Share on other sites More sharing options...
adipalmer123 Posted May 8, 2011 Author Share Posted May 8, 2011 Anyone any ideas with this? Quote Link to comment https://forums.phpfreaks.com/topic/235623-301-redirects-with-php/#findComment-1212096 Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235623-301-redirects-with-php/#findComment-1212138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.