2016-06-09 82 views
0

我一直在开发基于WordPress的以下网址mytourismdata.tourism.gov.my这个网站,但是,他们希望他们的网站能够通过提及的URL和www.mytourismdata访问。 tourism.gov.my(与www。)这对我来说是非常奇怪的,因为我不知道这是否可能。www + WordPress的子域名问题

我一直在努力解决这个问题,但我从来没有见过任何人试图访问他们的网站使用该结构。有没有人曾经遇到过这个问题?你是如何解决它的?

Ps。该网站托管在Windows服务器上。

回答

0

你可以试试这个代码在你的.htaccess

请改变你的域名,而不是example.com.com

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^example.com$ 

RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 
+0

另一种方式是经过数据库和更改所有的URL –

+0

用这种方式,人们能仍然mytourismdata.tourism.gov.my访问或者只是www.mytourismdata.tourism.gov.my? – scottymorg

+0

即使你将尝试访问没有万维网它将改为www.example.com –

3

您必须修改服务器上的.htaccess文件。这样你的服务器就可以通过www(www.mytourismdata.tourism.gov.my)了解即将到来的请求,并将重定向到非www的网址mytourismdata.tourism.gov.my。最终会发生的是,URL上的每个请求都会自动重定向到mytourismdata.tourism.gov.my。所以,你将能够

使用访问您的网站下面的代码

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

希望这会有所帮助。

编辑:

就像你说的你使用的是Windows服务器。因此,您已经知道必须使用以下代码更改web.config file.try。

<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> 

更改域名与您的域名。 希望它能适用于子域。

+0

Thunank你这么多。但是,我忘了提及该网站托管在Windows服务器上。有可能将其转换为web.config?谢谢 – scottymorg

+0

编辑了我对web.config相关更改的回答。 –

+0

非常感谢你:) – scottymorg

1

您必须编辑服务器上的web.config文件,才能在您的wordpress中进行所需的更改。在web.config文件中放置以下代码。

<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>