PDA

View Full Version : How to redirect site.com to www.site.com?


Bouncer222
12-11-2010, 02:42 PM
As the title says... How to redirect site.com to www.site.com?

How would I go about doing this? my site is www.fragtoss.com so how would I make it so that when people type fragtoss.com it sends them to www.fragtoss.com ?

Thanks.

K!nG
12-11-2010, 02:47 PM
That's something that will happen automatically when ppl will type fragtoss.com their browser will automatically take them to your homepage with as http://fragtoss.com

Bouncer222
12-11-2010, 02:51 PM
Well since I'm asking how to do it, it's obviously not happening :)

K!nG
12-11-2010, 03:07 PM
what server your website is hosted on ?? Windows / Linus ? i can try to help u once i know that or u can do that on ur own by redirecting 301 nonwww to www url. u can search for .... 301redirect also on ur own if u want.

Bouncer222
12-11-2010, 03:30 PM
mine is linux

Weetabix
12-11-2010, 04:09 PM
You can use htaccess to do this;

http://snippetdb.com/htaccess/add-www

very very very very useful little file, capable of tons of great stuff. If you've never used it before, visit http://www.askapache.com/ for usage and examples.

Bouncer222
12-11-2010, 07:38 PM
So where should I place...

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

In this, which is my .htaccess file?

# Comment the following line (add '#' at the beginning)
# to disable mod_rewrite functions.
# Please note: you still need to disable the hack in
# the vBSEO control panel to stop url rewrites.
RewriteEngine On

# Some servers require the Rewritebase directive to be
# enabled (remove '#' at the beginning to activate)
# Please note: when enabled, you must include the path
# to your root vB folder (i.e. RewriteBase /forums/)
#RewriteBase /

#RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
#RewriteRule (.*) http://www.yourdomain.com/forums/$1 [L,R=301]

RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]

RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron|vbseo_sitemap)
RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/(admincp|modcp|clientscript|cpstyles|images)/
RewriteRule ^(.+)$ vbseo.php [L,QSA]

## Expires
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 3456000 seconds"
ExpiresByType image/jpeg "access plus 3456000 seconds"
ExpiresByType image/png "access plus 3456000 seconds"
ExpiresByType text/css "access plus 3456000 seconds"
ExpiresByType text/javascript "access plus 3456000 seconds"
ExpiresByType application/javascript "access plus 3456000 seconds"
ExpiresByType application/x-javascript "access plus 3456000 seconds"
</ifModule>

## Compression
<ifmodule mod_headers.c>
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/xml application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</ifmodule>
</ifmodule>

## Rewrites
<ifmodule mod_rewrite.c>
RewriteEngine on
Options +FollowSymlinks

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# Media Library
ReWriteRule ^media/m(\d+).*/tags$ media.php?do=tags_edit&mid=$1 [QSA]
ReWriteRule ^media/m(\d+).*/edit$ media.php?do=details_edit&mid=$1 [QSA]
ReWriteRule ^media/m(\d+).*/report$ media.php?do=report&mid=$1 [QSA]
ReWriteRule ^media/m(\d+).*/c(\d+)$ media.php?do=comment_edit&cmt=$2 [QSA]
ReWriteRule ^media/m(\d+).*/p(\d+).*$ media.php?do=details&mid=$1&pid=$2 [QSA]
ReWriteRule ^media/m(\d+).* media.php?do=details&mid=$1 [QSA]
ReWriteRule ^media/p(\d+).*/edit$ media.php?do=playlist_edit&pid=$1 [QSA]
ReWriteRule ^media/p(\d+).* media.php?do=playlist&pid=$1 [QSA]
ReWriteRule ^media/c(\d+).* media.php?do=category&cid=$1 [QSA]
ReWriteRule ^media/u(\d+).* media.php?do=user&uid=$1 [QSA]
ReWriteRule ^media/tag/(.*) media.php?do=tag&tid=$1 [QSA]
ReWriteRule ^media/results/(.*) media.php?do=results&query=$1 [QSA]
ReWriteRule ^media/advresults/(.*) media.php?do=advresults&query=$1 [QSA]
ReWriteRule ^media/letter/(.*) media.php?do=letter&query=$1 [QSA]
ReWriteRule ^media/browse.* media.php?do=browse [QSA]
ReWriteRule ^media/search.* media.php?do=search [QSA]
ReWriteRule ^media/random.* media.php?do=random [QSA]
ReWriteRule ^media/submit.* media.php?do=submit [QSA]
ReWriteRule ^media/tagcloud.* media.php?do=tagcloud [QSA]
ReWriteRule ^media/playlists.* media.php?do=playlists [QSA]
ReWriteRule ^media/pcreate.* media.php?do=playlists_create [QSA]
ReWriteRule ^media/pmine.* media.php?do=playlists_mine [QSA]
ReWriteRule ^media/favorites.* media.php?do=favorites [QSA]
ReWriteRule ^media/subscriptions.* media.php?do=subscriptions [QSA]
ReWriteRule ^media/admin/edit/s(\d+).* media.php?do=admin_host_edit&sid=$1 [QSA]
ReWriteRule ^media/admin/delete/s(\d+).* media.php?do=admin_host_delete&sid=$1 [QSA]
ReWriteRule ^media/admin/export/s(\d+).* media.php?do=admin_host_export&sid=$1 [QSA]
ReWriteRule ^media/admin/(\w+).* media.php?do=admin_$1 [QSA]

# Media Library from Video Directory
RewriteCond %{QUERY_STRING} do=viewdetails&videoid=(\d+)
RewriteRule ^video\.php$ media.php?do=details&mid=%1
RewriteCond %{QUERY_STRING} viewcategory&categoryid=(\d+)
RewriteRule ^video\.php$ media.php?do=category&cid=%1
RewriteCond %{QUERY_STRING} viewuser&userid=(\d+)
RewriteRule ^video\.php$ media.php?do=user&uid=%1
RewriteCond %{QUERY_STRING} viewtag&tag=(.*)
RewriteRule ^video\.php$ media.php?do=tag&tid=%1
ReWriteRule ^video\.php$ media.php

# Forum
RewriteRule ^threads/.* showthread.php [QSA]
RewriteRule ^forums/.* forumdisplay.php [QSA]
RewriteRule ^members/.* member.php [QSA]
RewriteRule ^blogs/.* blog.php [QSA]
ReWriteRule ^entries/.* entry.php [QSA]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

# MVC
RewriteRule ^(?:(.*?)(?:/|$))(.*|$)$ $1.php?r=$2 [QSA]
</ifmodule>

Weetabix
12-11-2010, 08:36 PM
You only need to use the 'RewriteEngine On' once, and you can stick that extra bit anywhere underneath it. Something like this;

RewriteEngine On

RewriteCond %{HTTP_HOST} ^fragtoss.com$
RewriteRule (.*) http://www.fragtoss.com$1 [R=301]

# Some servers require the Rewritebase directive to be
# enabled (remove '#' at the beginning to activate)
# Please note: when enabled, you must include the path
# to your root vB folder (i.e. RewriteBase /forums/)
#RewriteBase /

#RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
#RewriteRule (.*) http://www.yourdomain.com/forums/$1 [L,R=301]

RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]

RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron|vbseo_sitemap)
RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]

preemz10314
12-11-2010, 08:45 PM
bro..why are you ppl telling this man such a complicated answer to an easy question.

Login to your host cpanel (not your vbulletin cpanel but your actual cpanel) , navigate to where you see redirects, then just add it there.

Weetabix
12-11-2010, 08:47 PM
Not every host has cpanel. I don't.

How on Earath is adding 2 lines of code into a pre-existing file considered complicated? If anyone has trouble with this, then installing mods or editing templates is gonna be quite a challenge. Besides, htaccess is a feather in any webmaster's cap.

preemz10314
12-11-2010, 09:13 PM
if he has cpanel all of that other code is a waste of time for such a minor issue. I swear some of you who help on this board think every one here has the same type of knowledge..no thats not true. It would be beneficial to give the most simple straight forward answer upfront then go from there.

Weetabix
12-11-2010, 09:20 PM
all of that other code is a waste of time for such a minor issue.

All of that other code is from VBSEO (http://www.vbseo.com/). I added 2 lines to it.


It would be beneficial to give the most simple straight forward answer upfront then go from there.

The answer I gave is a simple cut and paste...... how much easier can I make it? Anyway, this thread is heading off topic. The OP has a couple of solutions to choose from now, so he can choose which one he's happy with.

Digital Jedi
12-11-2010, 09:55 PM
if he has cpanel all of that other code is a waste of time for such a minor issue. I swear some of you who help on this board think every one here has the same type of knowledge..no thats not true. It would be beneficial to give the most simple straight forward answer upfront then go from there.
If you think it was mistake to think everyone has the same kind of knowledge, it was also a mistake to think everyone has cPanel. That's installed by the host, entirely at his/her discretion. And like Weetabix said, it's just two short lines of code to copy/paste. If that's too hard for a vB owner, then doing a template edit will blow their mind.

Bouncer222
12-12-2010, 02:45 AM
Well I appreciate everyone hurding over here to help me out.
Yet my question remains un-answered.

Where in the .htaccess should I place it? I'm not sure if just placing it at the end might have an affect on it? Or should it be placed at a certain point?

And yes I also have cpanel but for some reason the redirect wasnt working right.

Anyway, would someone mind answering the question?

--------------- Added 1292129313 at 1292129313 ---------------

You only need to use the 'RewriteEngine On' once, and you can stick that extra bit anywhere underneath it. Something like this;

RewriteEngine On

RewriteCond %{HTTP_HOST} ^fragtoss.com$
RewriteRule (.*) http://www.fragtoss.com$1 [R=301]

# Some servers require the Rewritebase directive to be
# enabled (remove '#' at the beginning to activate)
# Please note: when enabled, you must include the path
# to your root vB folder (i.e. RewriteBase /forums/)
#RewriteBase /

#RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
#RewriteRule (.*) http://www.yourdomain.com/forums/$1 [L,R=301]

RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]

RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron|vbseo_sitemap)
RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]


Didn't notice this from my previous post, but anyway, I added the 2 lines where you showed me, but it didn't work. Nothing happened.

Digital Jedi
12-12-2010, 04:06 AM
I have no idea if this will work, I'm merely going on an unsubstantiated hunch:


#RewriteCond %{HTTP_HOST} !^fragtoss\.com
#RewriteRule (.*) http://www.fragtoss.com$1 [L,R=301]

Bouncer222
12-12-2010, 04:40 AM
don't work

K!nG
12-12-2010, 08:28 AM
Hey budd m providin u this video tutorial abt redirecting 301... hope that helps you and if still not then sorry mate.

http://www.youtube.com/watch?v=VyEu99qWk3Q

preemz10314
12-12-2010, 10:56 AM
Asking most of these ppl for help will never work, they will give you some type of quantum theory answer to solve a simple redirect issue.

Do you have cPanel? Bouncer, like i said, if you have cPanel, just login to your host navigate to redirects and add it there. You have not said if you have cPanel or not...

Weetabix
12-12-2010, 11:36 AM
put this immediately after 'RewriteEngine On'


Options +FollowSymLinks

### Add www.

rewritecond %{http_host} ^fragtoss.com [nc]
rewriterule ^(.*)$ http://www.fragtoss.com/$1 [r=301,nc]

Digital Jedi
12-12-2010, 03:13 PM
Asking most of these ppl for help will never work, they will give you some type of quantum theory answer to solve a simple redirect issue.

Do you have cPanel? Bouncer, like i said, if you have cPanel, just login to your host navigate to redirects and add it there. You have not said if you have cPanel or not...
Yes he did. He said it wasn't working right there, either (https://vborg.vbsupport.ru/showthread.php?p=2132678#post2132678). I guess those two sentences, like the two lines of code offered, were also a little too quantum-y.

We're trying to help someone root out a problem by giving him steps to try and eliminate as possible solutions. You're just mocking the people trying to help him, repeating a suggestion that if you had even bothered to fully read his posts you would already know doesn't work and cluttering up the thread with unhelpful information.

Everyone here offers their help free of charge and at the expense of their own free time. If you have something new to add, the it will be appreciated and taken in good faith. But if all you're going to do is conflate the simplest, most bone-headedly easy of steps into something ridiculously harder then it is, then I can only assume your just here to troll, not help.

Bouncer222
12-12-2010, 04:16 PM
put this immediately after 'RewriteEngine On'


Options +FollowSymLinks

### Add www.

rewritecond %{http_host} ^fragtoss.com [nc]
rewriterule ^(.*)$ http://www.fragtoss.com/$1 [r=301,nc]


Doesn't work.

Maybe there's something else in the .htaccess which I posted before that's conflicting?

Or how about this..

Anyone have their method ACTUALLY WORK on their own forums? I mean kinda pointless posting this stuff here if it doesn't work. I would appreciate it if someone tested it on their own forums first.

Thanks.

Weetabix
12-12-2010, 04:29 PM
Strange, that code USED to work fine for me........

edit> http://bfb-online.com wont work, but if you type bfb-online.com into your address bar it works.

Digital Jedi
12-12-2010, 06:23 PM
Doesn't work.

Maybe there's something else in the .htaccess which I posted before that's conflicting?

Or how about this..

Anyone have their method ACTUALLY WORK on their own forums? I mean kinda pointless posting this stuff here if it doesn't work. I would appreciate it if someone tested it on their own forums first.

Thanks.
This is how it looks on mine.

RewriteEngine on
rewritecond %{http_host} ^cogonline.net [nc]
rewriterule ^(.*)$ http://www.cogonline.net/$1 [r=301,nc]

Seems to be identical to yours, and it's been working for years. In fact, this is what cPanel wrote in. So something more must be going on here.

http://www.cogonline.net | http://cogonline.net

Weetabix
12-12-2010, 06:26 PM
DNS not resolving the 2 part domain, rather than something wrong with the code?

Digital Jedi
12-12-2010, 06:29 PM
The SEO wouldn't be messing with it, would it?

Weetabix
12-12-2010, 06:37 PM
Just noticed;

# Comment the following line (add '#' at the beginning)
# to disable mod_rewrite functions.
# Please note: you still need to disable the hack in
# the vBSEO control panel to stop url rewrites.
RewriteEngine On

# Some servers require the Rewritebase directive to be
# enabled (remove '#' at the beginning to activate)
# Please note: when enabled, you must include the path
# to your root vB folder (i.e. RewriteBase /forums/)
#RewriteBase /

#RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
#RewriteRule (.*) http://www.yourdomain.com/forums/$1 [L,R=301]

RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]

The code seems to be there already, just remove the # and put your domain in there. TBH though, you're probably better off asking at the vBSEO forums just in case their rules are somehow affecting this as Jedi suggests. There seems to be plenty of threads about it.

edit> this thread looks promising LINKY (http://www.vbseo.com/f9/www-has-gonne-missing-46388/)

Bouncer222
12-12-2010, 07:08 PM
yeah i noticed later before u posted that, that the yourdomain.com needed to be changed, although I forgot to remove the number sign to uncomment it.

I also removed forums/ since my forums are in the root. It's all fixed now thank you all.

Digital Jedi
12-13-2010, 12:24 AM
That's where I got the first suggestion I posted, but didn't realize it needed to be the actual two lines with the hashtags removed and not just duplicated. Good to know.

FReeSTER
12-13-2010, 02:44 PM
Well I have the same issue and have posted here but nothing happen to get it to work correctly. It give me error 404
I currently using the http:// right now but never been able to fix it to work on www instead

Any ideas?

Digital Jedi
12-13-2010, 10:10 PM
The http:// should always be there, www or not. What this is, is directing one without to one with. Is that what you were going for?

SystemOAD
12-14-2010, 11:40 AM
This is the code I have always used in my htaccess files:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^YOURDOMAIN.com
RewriteRule (.*) http://www.YOURDOMAIN.com/$1 [R=301,L]
Keep it at the top as you where told (with the change of that second line) and it should work fine mate.

Also check that your host accepts the use of htaccess files as some do NOT allow them to be used. In which case you need to ask your host to allow the use of htaccess.