View Full Version : Redirecting to www - .htaccess
hofmax
05-07-2007, 01:53 PM
Ok I thought I know how to do this. I just want to redirect my blog (look at sig link) to www.cheap..../blog
This is what I used
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^yourhomepage.com [nc]
rewriterule ^(.*)$ http://www.yourhomepage.com/$1 [r=301,nc]
but it didnīt work
since I didnīt have any success with that I googled around and found someone who did this with php which brought me a bit closer to the solution.
He used this:
<?php
$host = $GLOBALS['HTTP_SERVER_VARS']['HTTP_HOST'];
$request = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'];
header("HTTP/1.0 301 Moved Permanently");
header("Location: http://www.$host$request");
header("Connection: close");
?>
I put that in my header.php but ended up getting
http://www.www.cheap-webhosting.in/blog/etcetera
Could someone tell me where I went wrong with the .htaccess or if you know what the error with the php is that would be helpful as well. Is register globals off or something?
cheers!
areidmtm
05-07-2007, 02:45 PM
I use this and it works for me
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$
RewriteRule ^(.*)$ http://www.domain.com [R=301,L]
hofmax
05-07-2007, 02:53 PM
Ok so as my main site is www. anyway I just need to redirect the stuff in my directory /blog/
would I use
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com/blog/$
RewriteRule ^(.*)$ http://www.domain.com/blog/ [R=301,L]
I put this .htaccess in the root folder of wordpress which is in /bog/
Is this correct?
areidmtm
05-07-2007, 05:32 PM
yes, put that in the .htaccess file in the blog folder
Basil
05-08-2007, 12:42 AM
This goes in the .htaccess file under public_html
RewriteEngine on
RewriteRule ^$ http://www.example.com/blog/$1 [r=301]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301]
1. Redirects base to /blog/
2. If there's no www it redirects to the www version
At least I think that's what you were asking..
hofmax
05-08-2007, 05:10 AM
Ok, thanks I will try your suggestions. Just some more info before I come back whining again :D
my signature website is in a subdirectory (addon domain). After I tried the php method with the headers, I got a double www everytime I tried to access my blog with the www prefix
like this
http://www.www.cheap-webhosting.in/blog/
Whatīs worse is that even though I deleted all files that could be responsible for this kind of redirection it still persists so I will probably just delete all files and re-upload the whole thing again.
hofmax
05-08-2007, 02:11 PM
I just found out that Firefox had cached my php headers redirect and added the extra www which made my head spin for a day :rolleyes:
The .htaccess redirect is not working for me unfortunately.
Pethens
05-08-2007, 02:27 PM
I hate to state the bleeding obvious, but the domain names in those redirect rules are just examples, you have to replace them with your actual domain name. Thus the following from your first post should work fine:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^cheap-webhosting.in [NC]
RewriteRule ^(.*)$ http://www.cheap-webhosting.in/$1 [R=301,NC]
Chances are you know this, but there's nothing wrong with the rules you have been given and they're still not working for you, so it's something to check.
hofmax
05-09-2007, 04:57 AM
Pethens, that was obvious but thanks anyway:p
...and it's still not working. Iīve been given slight variations of these rules over the past couple of days by different people and I know that they should work in theory and the fact that they donīt is slowly but surely driving me mad.
Is it possible that a higher level .htaccess even though it doesnīt contain any redirects concerning http://www.cheap-webhosting.in is causing problems?
This is where I put the directive - cheap-webhosting is an addon domain.
/maindomain.com/
/maindomain.com/cheap-webhosting/
/maindomain.com/cheap-webhosting/blog/
This is the folder where I put the .htaccess with the rewrite rule /maindomain.com/cheap-webhosting/.htaccess
Any suggestions or is it time to contact support. However since last time support decided to switch off my .htaccess completely Iīm slightly reluctant.
cheers!
Basil
05-09-2007, 10:43 AM
What's in the higher-level htaccess file?
I just found out that Firefox had cached my php headers redirect and added the extra www which made my head spin for a day :rolleyes:
The .htaccess redirect is not working for me unfortunately.
I hate to admit it but this gets me all the time. :)
To make another "bleeding obvious" statement, check that you don't have something somewhere else in the file counteracting what you're doing. I use what Basil suggested and it works fine.
hofmax
05-09-2007, 01:24 PM
What's in the higher-level htaccess file?
nice post count 444 :cool:
thatīs for my root domain - cheap - webhosting .in is an addon domain so it shouldnīt really interfere.
The only directives in the root domain .htaccess are redirects particular to that site plus anti hotlinking directives.
Powered by vBulletin™ Version 4.0.6 Copyright © 2010 vBulletin Solutions, Inc. All rights reserved.