Website funktioniert ohne das Präfix www

718
TelexVni

Ich arbeite zum ersten Mal an IIS. Meine Website funktioniert nur ohne das WWW-Präfix. Wenn ich ein: Link funktioniert es gut, aber wenn ich mit www eingeben wie hier gibt sie „Datei nicht gefunden“. Der Cname-Datensatz ist bereits vorhanden.

-1
`Der Cname-Datensatz existiert bereits. 'Damit gelangt er zur richtigen IP. HTTP ist jedoch ein spezielles Protokoll, es sendet auch den Hostnamen in seinen Anforderungen. Was bedeutet, dass Sie Ihren Webserver so konfigurieren müssen, dass er auch für ein anderes Ziel antwortet (das mit dem Präfix "www"). Hennes vor 8 Jahren 0

1 Antwort auf die Frage

1
a CVn

The host name portion of the URL is included separately in the HTTP request, and is used by the web server to select the virtual host that should be used to service the request.

Additionally, there is nothing magical about the www. prefix; as far as the web server is concerned, www.example.com and example.com are two entirely separate virtual hosts.

What you need to do is add a separate host name that either is an alias to the existing one, or a redirection host. I very strongly recommend that you do the latter, but am including both for completeness.

Alias (quick but dirty):

  • Open IIS Manager
  • Expand the host node
  • Expand the "Sites" node
  • Locate the web site node for your web site, right-click on it, and pick Edit bindings
  • In the Site bindings dialog, click Add
  • Select the correct type, IP address and enter the correct port. Enter the host name (www.example.com) in the provided text box. Click OK and Close.
  • Verify that the configuration works as intended

After making these changes, the two names will function identically, but will be considered distinct by any clients.

Redirection (recommended):

  • Open IIS Manager
  • Expand the host node
  • Right-click on the "Sites" node and click Add website
  • Configure the web site as appropriate, and point it at an empty root directory. Give it the host name that currently does not work.
  • Select the newly configured site in the sidebar
  • Open HTTP Redirect (you will find it under the IIS category in the Features View)
  • Configure redirection to the canonical host name, using Permanent (301) status, and Apply the changes

This should cause any requests that come to the redirection host name to be automatically redirected to the corresponding location at the canonical host name. This ensures that search engines don't see two identical sites at different URLs, which is often seen as a bad sign. Using Permanent redirections means that any clients should cache the redirection response, saving them a few steps in getting to your site in the future thus improving performance for returning visitors.