News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

something about .htaccess?

Started by diplomat., July 13, 2004, 04:55:35 PM

Previous topic - Next topic

diplomat.

i wanted to know how do i get my site to redirect whenever someone types in the url without the 'www' prefix to the url with the 'www'.

like, if someone types in:
http://titaniumwg.com or titaniumwg.com

it automatically goes to:
http://www.titaniumwg.com

how do i make this possible for all my directories and stuff....im such a n00b :-[
avidSOUND.com: Where Aspiring Musicians Can Be HEARD!

The Mole

If your files for http://titaniumwg.com [nofollow] and http://www.titaniumwg.com [nofollow] are in different locations, eg titaniumwg.com [nofollow] is /usr/local/www/data/mypage/ and www.titanium.wg.com [nofollow] is in /usr/local/www/data/myotherpage/ you could put this in your .htaccess file (in your root directory of titaniumwg.com [nofollow]:

Redirect / /http://www.titaniumwg.com [nofollow]

So long as you're not using anything else on just titaniumwg.com [nofollow], and your httpd.conf has different locations for your domains, that should be fine. If not, I'm not sure how you could do it with .htaccess...

In php you could put this in your header:

<?php
if($_SERVER['HTTP_HOST']=="titaniumwg.com")
        echo 
'<META HTTP-EQUIV="Refresh" CONTENT=".001; URL=http://www.titaniumwg.com">';
?>



-the mole

diplomat.

#2
in my /usr/local/ directory, i dont have a 'www' folder in it. what exactly does that mean?

also, i dont exactly know much about the .htaccess and stuff like that. is there already a .htaccess file on my server if i had not put one there? if not, where would i upload it? :'(
avidSOUND.com: Where Aspiring Musicians Can Be HEARD!

Cypher7

you don't have to worry about .htaccess for this... by default there is no htaccess file uploaded and you have to create it yourself... but its main use is for restricting files being linked from your site to others...

the redirect script that The Mole posted would do fine... except Im not sure but you may have to put that on every page, cos if someone enters your site at http://titaniumwg.com/something.php then it won't redirect unless the php is in the header of that page...?

Just a question, why do you want this redirection? Is it a visual thing or are file location reason?

The Mole

Quote from: Cypher7 on July 13, 2004, 07:16:36 PM
the redirect script that The Mole posted would do fine... except Im not sure but you may have to put that on every page, cos if someone enters your site at http://titaniumwg.com/something.php [nofollow] then it won't redirect unless the php is in the header of that page...?

Yeah, it would have to be in the header on every page.not really a problem if you're including/requiring your header though.

-the mole

The Mole

Quote from: DiplomaT on July 13, 2004, 05:59:27 PM
in my /usr/local/ directory, i dont have a 'www' folder in it. what exactly does that mean?

also, i dont exactly know much about the .htaccess and stuff like that. is there already a .htaccess file on my server if i had not put one there? if not, where would i upload it? :'(

I'm talking about the path to your files for your site. If the files for "www.titaniumwg.com" are located in a differrent place than just "titaniumwg.com" (this is done using virtual hostings) you could setup a .htaccess file to do what you want.

Here's a nice tutorial on .htaccess files
http://wsabstract.com/howto/htaccess.shtml [nofollow]

Let me know if you have any other questions...

-the mole

diplomat.

#6
Quote from: Cypher7 on July 13, 2004, 07:16:36 PM

Just a question, why do you want this redirection? Is it a visual thing or are file location reason?

really, its a cookie thing on my main site, my color changer, and on the forums. if im logged into the forums using the 'www', then go back to the forums without the 'www', im not logged in. thats the main reason....plus it would split my google pagerank between the two urls, like it did my other site.

also, ive seen this on some other sites like gamespot.com. thats what i meant :(
avidSOUND.com: Where Aspiring Musicians Can Be HEARD!

diplomat.

guys, i was able to get it done by putting


RewriteEngine on
RewriteCond %{HTTP_HOST} ^titaniumwg\.com$ [NC]
RewriteRule ^.*$ http://www.titaniumwg.com%{REQUEST_URI} [R=301,L]


in a .htaccess file  :)

thanx for all your help Cypher and Mole. i really appreciate it :D
avidSOUND.com: Where Aspiring Musicians Can Be HEARD!

Advertisement: