2011-06-29 10 views
8

Stackoverflowには多くの例がありますが、私はまだ何か不足しています。htaccess:古いドメインとすべてのページを新しいドメインにリダイレクトします

私は以下のルールでhttp://brand.new-domain.com/fr/http://old.domain.com/fr/をリダイレクトしようとしているが、それは動作しません:

# Enable Rewrite Engine 
RewriteEngine On 
RewriteBase/

# Add a trailing slash to paths without an extension 
RewriteCond %{REQUEST_METHOD} !=POST 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule ^(.*)$ $1/ [L,R=301] 

# Redirect domain 
Options +FollowSymLinks 
RewriteCond %{HTTP_HOST} ^old.domain.com [OR] 
RewriteCond %{HTTP_HOST} ^other-old.domain.com [NC] 
RewriteRule ^(.*)$ http://brand.new-domain.com/$1 [r=301,L] 

# Remove index.php 
# Uses the "exclude method" 
# http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Exclude_List_Method 
# This method seems to work best for us, you might also use the include method. 
# http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Include_List_Method 
# Exclude root files 
RewriteCond $1 !^(index\.php) [NC] 
# Exclude EE folders 
RewriteCond $1 !^(assets|ee-admin|images|templates|themes|fr|nl)/ [NC] 
# Exclude user created folders 
RewriteCond $1 !^(assets|css|img|js|swf|uploads)/ [NC] 
# Exlude favico, robots, ipad icon 
RewriteCond $1 !^(favicon\.ico|robots\.txt|pple-touch-icon\.png) [NC] 
# Remove index.php 
RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC] 
RewriteCond %{QUERY_STRING} !^(URL=.*)$ [NC] 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

私はページを呼び出すときにそれが正しく、私はルートURLを呼び出すときにリダイレクトではなく。私は間違って何をしていますか?

ありがとうございます!

Pvの

答えて

9

mod_rewriteのルールを書き込む場合、ルールは表示される順番で適用されます。

が新しいドメインに古いドメインをリダイレクトするには、そのルールが—他のすべてのルールが後に表示されるあなたの.htaccesshttpd.confファイルの最初のになりたいでしょう。あなたが唯一の特定のディレクトリをリダイレクトにしたい場合は、サイトの残りの部分は正常に機能することを可能にしながら、

は、次のルールでは、そうします:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # Redirect Only Matching Directories 
    RewriteCond %{REQUEST_URI} ^/(fr|fr/.*)$ 
    RewriteRule ^(.*)$ http://brand.new-domain.com/fr/$1 [R=301,L] 
</IfModule> 

あなたはサイト全体をリダイレクトしたい場合は、次のルールがそうします:あなたはクローラをさせる気にあなたのコンテンツが移動している知っているし、可能な限りの移行がシームレスにしたい場合は

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # Redirect Entire Site to New Domain 
    RewriteCond %{HTTP_HOST} ^old.domain.com$ [OR] 
    RewriteCond %{HTTP_HOST} ^other-old.domain.com$ [NC] 
    RewriteRule ^(.*)$ http://brand.new-domain.com/$1 [R=301,L] 
</IfModule> 

301 RedirectフラグIを保つようにしてくださいn RewriteRule

これにより、ユーザーと検索エンジンが正しいページに確実に誘導されます。


私たちが対象にしているが、EE 2.2リリースの一部として、EllisLabは現在、「公式に」removing index.php from ExpressionEngine URLsための限られた技術サポートを提供しています。

単にあなたがすでに所定の位置に持っている可能性のあるルールを検討して確認して、次のようにコードを追加または更新:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # Removes index.php 
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ /index.php/$1 [L] 

    # If 404s, "No Input File" or every URL returns the same thing 
    # make it /index.php?/$1 above (add the question mark) 
</IfModule> 
3

最初のものとして、次のrukeを使用してみてください:

# Redirect domain 
Options +FollowSymLinks 
RewriteCond %{HTTP_HOST} ^old.domain.com [OR] 
RewriteCond %{HTTP_HOST} ^other-old.domain.com [NC] 
RewriteRule ^(.*)$ http://brand.new-domain.com/$1 [R=301,L] 

またアッパーケースRを気には、下ケースredirectの短縮形です。

1

あなたはmod_alias、単純なリダイレクト命令(あなたが持っているコアモジュール)を使用してみましたhacky-mod-rewriteを試す前に?

私はServerName old.domain.comでのVirtualHostをするでしょうし、このVHに私は、このルールを追加します:DOCから

Redirect /fr http://brand.new-domain.com/fr 

を:

そして、URLパスで始まるすべての要求がリダイレクト要求を返します。ターゲットURLの場所にあるクライアントに送信します。一致したURL-Path以外の追加パス情報がターゲットURLに追加されます。

brand.new-domain.com(ServerName brand.new-domain.com)とは別のVirtualHostを取得します。この場合、リダイレクトルールは設定されません。

同じVirtualHostで2つのドメインを処理したい場合は、RedirectMatchでもクエリのリクエストドメインを確認できないため、mod-rewriteを使用する必要があります。

関連する問題