2017-08-26 1 views
1

ダイナミックドメイン名で(R301)をリダイレクト:.htaccessの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を。」。 .. www。 froschkoenig84。置き去りにされた。ネット www。 froschkoenig84。デ

"www。"で始まっていないとき。次いで、追加そうではない...

するRewriteRule ^(WWW?[\])http://www.% {HTTP_HOST}%{REQUEST_URI} [R = 301、L]

しかし、それはdoesnのそれは毎回追加されているので、終わりのようです... add "www." each time

"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> 

を:/

答えて

1

ドメイン名はするRewriteRuleのテストURIの一部ではありません。

あなたは使用することができます。

RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L] 
+1

おかげで、。 :) – Froschkoenig84

0

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] 
関連する問題