문제

I'm running php on IIS 8.0.

when I enter the site address with www server returns IIS Error 500. with out www everything is OK.

How can I automatically remove www from adress.

도움이 되었습니까?

해결책

you can use url rewrite module

add this code to web.config and replace domain.tld with your domain name

<rule name="Remove www" stopProcessing="true"> <match url="^(.*)$" /> <conditions> <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" /> </conditions> <action type="Redirect" url="http://domain.tld{PATH_INFO}" /> </rule>

다른 팁

There are multiple ways to redirect your site to domain only, 1) using DNS server, in DNS you can redirect your visitors to domain only, 2) using IIS config file -> C:\Windows\System32\inetsrv\config.

You don't want to simply redirect because you will have to do that for every page and subdomain. My code will auto strip the www. for you.

.htaccess code

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

If you want to fix you DNS issue just add a 'A' record with www.yourwebsite.com

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top