0

我在1&1的Windows服務器上託管了我的網站。 在那裏,不可能添加在web.config元素<rewrite><rules> ...所以我使用的是.htaccess文件... 我不是那麼專業,我預計它只會在Apache服務器上工作。我錯了!我的.hataccess也適用於IIS。在IIS上使用301從非www到www的重定向

下面的代碼:

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

//Prevent viewing of .htaccess file 
<Files .htaccess> 
order allow,deny 
deny from all 
</Files> 

重定向使用302我要301重定向完成的問題。我使用的小提琴手,這是結果:

enter image description here

的網站,我的問題是www.renovahaus.it 我怎樣才能解決我的問題?

感謝名單

回答

0

這通常與URLRewrite模塊完成,在1 & 1這種情況在web.config然而,當您使用.htaccess文件中的.htaccess的內容仍然翻譯被禁用到底層的web.config。

您可以在轉換過程here

讀了偉大的教程,但摘要是你可能尋找的代碼塊: -

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

原本應該透明地添加以下到網上。配置文件(即使你不能直接編輯它)

<rewrite> 
    <rules> 
    <rule name="Imported Rule 1" stopProcessing="true"> 
     <match url="^(.*)$" ignoreCase="false" /> 
     <conditions> 
     <add input="{HTTP_HOST}" pattern="^example\.com$" /> 
     </conditions> 
     <action type="Redirect" redirectType="Permanent" url="http://www.example.com/{R:1}" /> 
    </rule> 
    <rule name="Imported Rule 2" stopProcessing="true"> 
     <match url="^(.*)$" ignoreCase="false" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> 
     <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" /> 
    </rule> 
    </rules> 
</rewrite> 
+0

但爲什麼.htaccess文件重定向使用302而不是301? – Ciccio