我想重定向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] 我的问题是这可能是一个不同的水平..。www。froschkoenig84。放好了。net。froschkoenig84。de
所以当它不是以“www”开头的时候。那就加一句,否则.
RewriteRule ^(?) 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>:/
发布于 2017-08-26 14:26:37
域名不是RewriteRule中的测试uri的一部分。
您可以使用:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]发布于 2017-08-26 15:35:09
worink解决方案:
DirectoryIndex index.php
RewriteEngine on
#RedirectToHome
RewriteRule ^$ /home/ [R=301,L]
#RedirectToWWW
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
#RewriteToParams
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=/$1 [QSA]https://stackoverflow.com/questions/45896387
复制相似问题