ServerAlias and RewriteRule

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

I originally set my virtual host up like this in my httpd.conf file:

<VirtualHost *:80>
    ....
    ServerName www.example.com
    ServerAlias example.com
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</VirtualHost>


Running curl to check the setup I get:
[$] curl example.com

Result:
---------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
...
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://www.example.com//";>here</a>.</p>
...
---------------------------------------------------

As you can see from the link "The document has moved . . . ", href is set to: href="http://www.example.com//";, 
i.e. with TWO slashes after and not ONE slash.

To fix it i changed the RewriteRule
From:
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
To:
    RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]

and now the "301 Moved Permanently" HTML page gives:
  The document has moved <a href="http://www.example.com/";>here</a>

Question 1)
Are there any problems running a):
	RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
Rather than b):
	RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
?
Will e.g. a slash always be added as a part of $1 in a) if it exists in the
original url query (as caught by the RewriteCond shown above)?

Question 2)
Is the method I use to alias "example.com" with "www.example.com",
a good way to set up a ServerAlias in my httpd.conf file, or are there better ways?
My current method, as mentioned above, is:
    ServerName www.example.com
    ServerAlias example.com
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]


Thanks for any input!

Richard Taubo
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx




[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux