Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect URLs with FQDN (dot after TLD) to equivalent with PQDN

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

  • https://www.ebay.com./
  • https://www.google.com./
  • https://www.reddit.com./
  • https://stackoverflow.com./
  • https://en.wikipedia.org./wiki/Main_Page

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)

like image 581
unor Avatar asked Nov 12 '22 18:11

unor


1 Answers

This should work :

RewriteCond %{HTTP_HOST} ^([a-z0-9\.-]+)\.com\.$ 
RewriteRule ^(.*) http://www.domain.com/$1  [QSA,L,R=301]
like image 88
Vince Avatar answered Nov 15 '22 07:11

Vince