PDA

View Full Version : 301 redirect, virtual hosting



droliff
Dec 22nd, 2008, 08:35 PM
Hi all,

Dennis here. I hope I am posting this question in the correct section of the forums. If not please let me know which section this question would best fit into.

I am new to this forum and looking for some expert advice on 'virtual hosting'.

I am with verio.com's webhosting service (their basic UNIX plan (http://www.verio.com/unix-hosting-plans/), and I've just moved to that plan from an older verio plan (the new plan costs half as much but seems to offer more, go figure :rolleyes:). My IP address and server have changed and I have made all the DNS modifications necessary. Everything seems to be in order now except one thing. When I was on the old plan I was able to 'virtual host' a website for a club that I am in, domain name laughingclubneo.com (The Laughing Club of Northeast Ohio). Domain was purchased through Godaddy.com and I changed the DNS numbers at Godaddy to point this domain to my new server with Verio. I was able to virtual host the laughing club site on my old verio server via a redirect by adding a .htaccess file to the root directory (http://www.verio.com/support/documents/view_article.cfm?doc_id=3624) (scroll down to 'redirect a machine name'). I am operating on a Mac Pro using OS 10.5.5 The instructions for creating the .htaccess file said to start with just the ".".
When I tried to save a file on my hard drive using text edit in ASCII or plain text mode I got a popup warning that any files saved using just a "." at the beginning were strictly for the system and would become invisible. Well this is what happened. So I named the .htaccess file vh.htaccess (vh for virtual hosting). Here is the code that I used in the file which worked on the previous plan/server to redirect the laughingclubneo.com domain to a folder in my root directory called laughingclubneo.com (http://dennisroliff.com/laughingclubneo.com/) :

<Files vh.htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} laughingclubneo.com$
RewriteCond %{REQUEST_URI} !laughingclubneo.com/
RewriteRule ^(.*)$ laughingclubneo.com/$1
<Files vh.htaccess>
order allow,deny
deny from all
</Files>

I tried adding this file to the root directory on my new Verio server and it isn't working. I was told by a Verio tech support person that they could not help me in writing a redirect code (even though a week before another Verio tech support guy had done just that :rolleyes: ) but said that I needed to Google and research something called a 301 redirect.

I googled '301 redirect' and accessed this tutorial (http://www.tamingthebeast.net/articles3/spiders-301-redirect.htm) which I couldn't really figure out, even though it seemed simpler than the other code, lol.

I am here to ask anyone if they can help me with this redirect code or process so that I can put a cap on this server/plan move and have everything working again.
I know that virtual hosting is possible and done all the time and I am confident that I will get some great suggestions here on this forum.

Thanks in advance for any input.

Best,

Dennis

rmedek
Dec 23rd, 2008, 01:34 AM
Not quite an HTML problem but what the hey…

First of all, you most likely don't need (or want) the "deny from all" rules in your .htaccess file. So the .htaccess file would read:


RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} laughingclubneo.com$
RewriteCond %{REQUEST_URI} !laughingclubneo.com/
RewriteRule ^(.*)$ laughingclubneo.com/$1

Next, if you don't have a text editor on your machine that can read hidden files, save it as "htaccess" (no dots) and when you FTP it to where it belongs, rename it ".htaccess" (dot!). The name is important.

Finally, what you're doing isn't technically virtual hosting, but more of using "mod rewrite" (the Apache module that is doing all of the stuff in that .htaccess file). Essentially, you're taking any request for another domain and rewriting the URL so it points to the domain you want the visitor to go to. Maybe it's semantics, but it'll help if you need to ask the question again later.

droliff
Dec 24th, 2008, 01:16 AM
Medek,

Thanks for the input. I tried your code and method of saving as just htaccess without the dot at the beginning. Here is what the code looked like:

<Files .htaccess>
</Files>
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} laughingclubneo.com$
RewriteCond %{REQUEST_URI} !laughingclubneo.com/
RewriteRule ^(.*)$ laughingclubneo.com/$1
<Files .htaccess>
</Files>

Should the 'REQUEST_URI' in this code be 'REQUEST_URL'?

I made sure I saved file in ASCII mode (with mac's 'textedit' program) and it saved on my hard drive as
htaccess (no dot ). I uploaded the file to the root directory of my website (a folder called 'htdocs') which is two directories into the root directory of my web server space (see jpegs for a visual)

http://dennisroliff.com/samples/explanation/visual.jpg

when I ftp'd the file I made sure my ftp client (transmit) was in ASCII transfer mode but I still got this popup warning http://dennisroliff.com/samples/explanation/warning.jpg.
I went ahead and transferred it the first time without switching to a 'auto' mode. When it showed up in my directory, I renamed the file by adding a 'dot' at the beginning of the file and it immediately disappeared. I don't know where it's going but needless to say I tried typing laughingclubneo.com into the address bar of my browser and it didn't redirect to the laughingclubneo.com directory on my server. So I am still trying to figure out how to get this rewrite mod (redirect) to work.
I looked at the Apache Module Mod Rewrite (http://www.apache.org/docs/mod/mod_rewrite.html) manual but it's too technical for me. I just want to get this 'redirect' working and I'll be a happy camper.
Should I rename the directory that I'm building the laughing club website something without a dot in the name? Why does the file htaccess disappear as soon as I add the 'dot' to it? Where does it go? Will it mess up my system if I keep adding different versions of this file? Does one rewrite over a previous .htaccess file?

Any suggestions?

Thanks.

Dennis