2017-08-02 208 views
-2

你如何強制根域使用?我想知道如何做到這一點的從www重定向。到根域(不含www。)

html, php, Javascript, .htaccess,jQuery, ajax. 

我知道元刷新

如下所示:

<meta http-equiv="refresh" content="0; url=http://example.com/" /> 

在這裏,我知道這太:

<body onload="window.location.href = 'your URL';"></body> 

以及:Php

<?php header('Location: https://example.com'); ?> 

但這些工作都不符合我的要求。 多種方法會很好!

+4

你嘗試搜索? https://stackoverflow.com/a/1270281/6468413 – JapanGuy

+2

這在你的服務器配置,看到你正在使用的文檔 – Kai

+1

@JapanGuy沒有工作 – antimalwareprogram

回答

1

確保您的htaccess重寫正在工作。

使用此對您的htaccess

RewriteEngine On 
RewriteBase/
Rewritecond %{HTTP_HOST} ^www\.yoursite\.com$ [NC] 
RewriteRule ^(.*)$ https://yoursite.com/$1 [R=301,L]