PDA

View Full Version : Another .htaccess redirect question...


bencharity
01-14-2009, 05:27 AM
Okay I am very new to .htaccess but have read a ton of posts/blogs but still can't get it to work.

I'm on GoDaddy hosting if that matters.

I need two rewrites, One I wish to rewrite the url so that when someone types in mysite.com it rewrites to www.mysite.com. I tried this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.come$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

but it didn't seem to work.

Also I need a redirect and block that stops everyone from accessing my site during construction. I need to be able to access it, I need to be able to validate it, and I want to let google index it. However whenever someone clicks a link, selects a bookmark, or types the address in I want them to be sent to a temp page. I tried this:

AuthName "Under Development"
AuthUserFile /home/askapache.com/.htpasswd
AuthType basic
Require valid-user
Order Deny,Allow
Deny from all
Allow from 1.1.1.1 w3.org googlebot.com google.com google-analytics.com
Satisfy Any

but since I'm a total newbie at this, I didn't really know how to tweak this for my purpose.

I'd love to learn this skill, so any help would be great.
Thanks!

abduraooft
01-14-2009, 09:41 AM
For your first need, try
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

bencharity
01-14-2009, 02:34 PM
Thanks for the reply! I'm uploading it now!

bencharity
01-14-2009, 03:18 PM
Ok, I uploaded that code as it was posted in a .htaccess file to my root folder. But now I'm just getting a '500 Internal Server Error'.

Any ideas?

abduraooft
01-14-2009, 03:37 PM
Ok, I uploaded that code as it was posted in a .htaccess file to my root folder. But now I'm just getting a '500 Internal Server Error'.

Any ideas?I don't think the error is due to the the code posted above, as it's taken from my working htaccess file. Have a try by commenting the other rules, if any. (Assume mod_rewrite is actually turned on in your server)

bencharity
01-14-2009, 06:07 PM
Ok I got it working!

I simply added Options +FollowSymlinks to the top creating this:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

and it worked! Thanks again!


P.S. still looking for the other code needed in case anyone else knows how to.