Jump to content
View in the app

A better way to browse. Learn more.

The Uniform Server Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

.htaccess to remove the "www" from URL

Featured Replies

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.

  • Author
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!

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...

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.