【发布时间】:2017-08-26 14:21:04
【问题描述】:
我想重定向 3 级或 4 级域以添加“www.”:
DirectoryIndex index.php
RewriteEngine on
RewriteRule ^$ /home/ [R=301,L]
RewriteRule ^(?!www[\.]) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=/$1 [QSA]
我的问题是它可能是不同数量的级别...... 万维网。弗罗施科尼格84。放置。网 万维网。弗罗施科尼格84。去
所以当它不是以“www”开头时。然后添加,否则不...
重写规则 ^(?!www[\.]) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
但它不起作用,......它每次都在添加......所以它的结尾就像......
如何检查它是否以“www”开头。或不? 如果可能,那么没有单独的条件。 :)
我也为 .NET (web.config) 创建了类似的重写规则:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RedirectToHome" stopProcessing="true">
<match url="^$" />
<conditions trackAllCaptures="true">
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{ToLower:{C:1}://{HTTP_HOST}/home/}" />
</rule>
<rule name="RedirectToWWW" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?://)(?!www[\.])" />
</conditions>
<action type="Redirect" url="{ToLower:{C:1}www[\.]{R:1}}" redirectType="Permanent" />
</rule>
<rule name="RewriteToParams" 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="{ToLower:index.php?p=/{R:1}}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
:/
【问题讨论】: