Reputation: 133
I have been developing this website in the following URL mytourismdata.tourism.gov.my which is based on Wordpress, however, somehow they want their website to be able to accessed either by the mentioned URL and www.mytourismdata.tourism.gov.my (with www.) which is quite bizarre to me as I have no idea if that's possible to do so.
I have been struggling trying to get this issue solved but I never seen anyone trying to access their website using that structure. Has anyone ever faced this issue before? How did you solve it?
Ps. The website is hosted on windows server.
Upvotes: 0
Views: 58
Reputation: 31
You have to edit web.config file on your server to make desired changes in your wordpress. Place following code in your web.config file.
<rewrite>
<rules>
<rule name="Redirect to non-www" topProcessing="true">
<match url="(.*)" negate="false"></match>
<action type="Redirect" url="http://domain.com/{R:1}"></action>
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com$" negate="true"></add>
</conditions>
</rule>
</rules>
</rewrite>
Upvotes: 1
Reputation: 573
You have to modify the .htaccess file on your server. So that your server will understand the upcoming request with www (www.mytourismdata.tourism.gov.my
) and will redirect to non www url mytourismdata.tourism.gov.my
. Ultimately what is happening is, Every request on the URL will be redirected to mytourismdata.tourism.gov.my
automatically. So you will be able to access your website with
use the following code
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Hope this will help.
EDITED :
Like you said you are using a windows server. So as you already know that you have to change web.config file.try useing the following code.
<rewrite>
<rules>
<rule name="Redirect to non-www" stopProcessing="true">
<match url="(.*)" negate="false"></match>
<action type="Redirect" url="http://domain.com/{R:1}"></action>
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com$" negate="true"></add>
</conditions>
</rule>
</rules>
</rewrite>
changed domain with your domain name. Hope it will work for subdomain aswell.
Upvotes: 3
Reputation: 601
you can try this code in your .htaccess
please change your domain instead of example.com.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Upvotes: 0