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