Redirect URLs with FQDN (dot after TLD) to equival

2020-04-11 03:04发布

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)

1条回答
小情绪 Triste *
2楼-- · 2020-04-11 03:17

This should work :

RewriteCond %{HTTP_HOST} ^([a-z0-9\.-]+)\.com\.$ 
RewriteRule ^(.*) http://www.domain.com/$1  [QSA,L,R=301]
查看更多
登录 后发表回答