3

Many websites can be accessed with a FQDN (i.e., appending a dot to the TLD):

Some sites can’t be accessed that way, but I can’t find an example right now.¹ ²

Is it possible, within a .htaccess file, to redirect all variants with the dot suffix to the variants without?

Ideally with a "wildcard" rule, so that you don’t have to list the domains explicitly (for using it on different sites/domains without editing).

Example redirects:

  • http://example.com./
    http://example.com/
  • http://example.com./foo
    http://example.com/foo
  • http://sub.example.com./bar.html
    http://sub.example.com/bar.html

¹ stackoverflow.com, when accessed over HTTP, used to give HTTP error 400: "Bad Request - Invalid Hostname".

² Wikipedia, when accessed over HTTPS (when it was still optional), used to give a certificate error: "The certificate is only valid for the following names: *.wikipedia.org , wikipedia.org (Error code: ssl_error_bad_cert_domain)

unor
  • 82,883
  • 20
  • 183
  • 315
  • duplicate from serverfault: http://serverfault.com/questions/251011/redirecting-to-canonical-domain – Daniel A. White Nov 09 '12 at 14:27
  • 1
    @Daniel: I can't find an answer there that could help me, nor is the question the same (no mention of dot after TLD). I know how to redirect a certain path to a certain domain(+path), and I know how to redirect a domain(+path) to a different domain(+path), but I'd like a "wildcard" solution that works for no-matter-which domain (if possible). – unor Nov 10 '12 at 02:31
  • @unor Can we chat, I have some doubts I want to ask? – Suraj Jain Dec 22 '17 at 03:35
  • @SurajJain: Chat room: https://chat.stackoverflow.com/rooms/161792/about-question-13309854 – unor Dec 22 '17 at 07:54

1 Answers1

1

This should work :

RewriteCond %{HTTP_HOST} ^([a-z0-9\.-]+)\.com\.$ 
RewriteRule ^(.*) http://www.domain.com/$1  [QSA,L,R=301]
Vince
  • 2,844
  • 1
  • 25
  • 26