Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: ServerNames with Trailing Dot |
|
Author |
|
jmweb
Joined: 08 Jun 2017 Posts: 22 Location: USA, Charlotte
|
Posted: Thu 27 Feb '25 6:13 Post subject: ServerNames with Trailing Dot |
|
|
What is the most efficient way to redirect requests for a hostname with a trailing dot to its dotless counterpart?
I considered creating a separate VirtualHost with the trailing dot variant as the ServerName, but it seems Apache strips the trailing dot automatically.
For example, I attempted the following configuration:
Code: |
<VirtualHost *:80>
ServerName domain.tld.
Redirect rule here
</VirtualHost>
|
However, Apache appears to normalize ServerName, treating both domain.tld. and domain.tld as the same, making this approach ineffective. |
|
Back to top |
|
jmweb
Joined: 08 Jun 2017 Posts: 22 Location: USA, Charlotte
|
Posted: Fri 28 Feb '25 5:43 Post subject: |
|
|
I was unable to offload the rewrite overhead to separate VirtualHosts set for hosts with trailing dots. Here is my solution in the event someone wants to accomplish the same.
Code: |
RewriteEngine on
<If "%{SERVER_PORT} =~ /^(80|443)$/">
RewriteCond %{HTTP_HOST} ^(.+?)\.+$
RewriteRule .? %{REQUEST_SCHEME}://%1%{REQUEST_URI} [R=301,END]
</If>
<Else>
RewriteCond %{HTTP_HOST} ^(.+?)\.+$
RewriteRule .? %{REQUEST_SCHEME}://%1:%{SERVER_PORT}%{REQUEST_URI} [R=301,END]
</Else>
|
|
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7399 Location: EU, Germany, Next to Hamburg
|
Posted: Tue 04 Mar '25 9:43 Post subject: |
|
|
I've never seen a domain in the wild ending with a dot.
I'm just curious why you have that. |
|
Back to top |
|
jmweb
Joined: 08 Jun 2017 Posts: 22 Location: USA, Charlotte
|
Posted: Tue 04 Mar '25 10:07 Post subject: |
|
|
James Blond wrote: | I've never seen a domain in the wild ending with a dot.
I'm just curious why you have that. | I created an httpd log analyzer that reports requests that fail to match specified host, request and referrer combinations. The script detected a invalid referrer but only because it contained a trailing dot. It is likely someone bookmarked the website and accidentally added a trailing dot. So, I would like to redirect these occurences.
1. https://www.google.com./ properly redirects.
2. https://www.apachelounge.com. fails with too many redirects.
3. https://httpd.apache.org./ supports it. |
|
Back to top |
|
|
|
|
|
|