Remove WWW prefix from your website

前端 未结 9 598
情歌与酒
情歌与酒 2020-12-28 19:24

How does Stack Overflow (and other web sites) remove the \'www\' prefix when it\'s entered as part of a URL?

Is it a redirect, a rewrite or something else entirely?<

相关标签:
9条回答
  • 2020-12-28 20:17

    This is going a long way back, but as far as I know this is a DNS setup. I think you don't need to specify a HOST address (WWW is the name of the host (or computer/cluster...) that the site resides on/in.).

    I think you can then set it up to send all requests to a default host.

    Not 100% sure, but check out what is possible with DNS.

    Hope that helps or at least get's you going in the right direction.

    0 讨论(0)
  • 2020-12-28 20:18

    On Apache, it looks like this (inside an .htaccess file):

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
    
    0 讨论(0)
  • 2020-12-28 20:25

    For apache

    <VirtualHost *:80>
    ServerName yourdomain.tld
    ServerAlias www.yourdomain.tld
    
    0 讨论(0)
提交回复
热议问题