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

断了今生、忘了曾经 提交于 2019-12-02 01:09:40

问题


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)


回答1:


This should work :

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


来源:https://stackoverflow.com/questions/13309854/redirect-urls-with-fqdn-dot-after-tld-to-equivalent-with-pqdn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!