Jump to content
The Uniform Server Community

.htaccess to remove the "www" from URL


gratzo
 Share

Recommended Posts

trying to figure out why I'm reaching the "root" folder of my Uniform Server when I don't type in the "www" in front of the URL. Works fine when I type "www.mydomain.com", but when I type in "mydomain.com", it resolves to the root folder, and not the virtual host set up.

 

Here is the detail behind this:

 

Uniform Server v3.2

vhost module installed and running

dynamic IP via dns.afraid.org

 

For the dynamic DNS entries, I have entered both of these to forward to the Uniform Server:

"mydomain.com"

"www.mydomain.com"

 

I know that part is working, because when you enter the URL's, both addresses hit the server, only one hits the virtual host, the other hits the root.

 

The virtual host entries in the config file are set to the following:

NameVirtualHost *
<VirtualHost *>
    Document Root /www/
    ServerName  localhost
</VirtualHost>

<VirtualHost *>
    Document Root /www/site1
    ServerName  www.mydomain.com
</VirtualHost>

 

I'm trying to do a rewrite with .htaccess to allow anyone to see the site on the virtual host with and without the "www". This is the code that I wrote into the .htaccess file, which obviously is NOT working correctly...and where I think I need the help

 

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

 

I know in theory this should work, I just have something twisted in either the .htaccess file, or in the virtual host (httpd) Apache config file.

 

Again, bottom line is (and I hope I'm not overcomplicating something that may be very simple) I'm just trying to resolve to the same place with and without "www" on my uniform server, with the virtual host running.

Link to comment
Share on other sites

Try removing www from the VHost code and test it. Just the mydomain.com :D

2037[/snapback]

 

OK, after stumbling upon a 2002 post about Apache Server, here's what I found, and it's pretty similar to your instructions. For each virtual host, I had to create another set of instruction - (for kicks, I tried putting it all in one "Virtualhost" command, but it didn't work):

 

This is the code that I put into the config file for the virtual host

<VirtualHost *>
   DocumentRoot /www/site1
   ServerName mydomain.com
</VirtualHost>

<VirtualHost *>
   DocumentRoot /www/site1
   ServerAlias www.mydomain.com
   Redirect permanent / http://mydomain.com
</VirtualHost>

 

So you don't have to look back and forth at the former code,

1. I removed the "www" in the "ServerName" line

2. Added the new "VirtualHost" section

3. created "ServerAlias" with www.mydomain.com

4. created the "Redirect permanent" line that points it to the new URL w/o the "www"

 

Nothing needed to be done to the .htaccess file, in fact, I took it out to make sure there was not effect.

 

Bottom line, this can be done via the Apache virtual domain and a simple bit of code in the config file. I hope this isn't just a fluke that it's working for me!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...