古いサイトから新しいサイトにページを1つずつリダイレクトします

StackOverflow https://stackoverflow.com/questions/1421419

質問

ページごとに、1つの新しいドメインのいくつかの古いドメインからページをリダイレクトしようとしています:

ページ1: http://www.example.org/default.asp? id = 1 http://www.example2.org/newpage.html ページ2: http://www.example2.org/default.asp?id=2 http://www.example.org/contact.html <にリダイレクトします

...など。古いページはすべて、特定の新しいページにリダイレクトされます。

.htaccessの行に沿って何かを書き込もうとしました

Redirect 301 http://www.example.org/default.asp?id=1 h-tp://www.example.org/newpage.html
Redirect 301 http://www.example2.org/default.asp?id=2 h-tp://www.example.org/contact.html

しかし、これまでのところ運はありません。 mod_aliasが有効になっています...

RewriteCondとRewriteRuleも次のように使用してみました:

RewriteCond %{HTTP_HOST} example.org
RewriteRule default.asp?id=1 http://www.example.org/newpage.html [NC,L,R=301]
...

言い換えれば、3つのサイト/ドメインを1つのサイトにマージするとともに、IDベースからエイリアスベースへのページごとのリダイレクトを実行したいです。

有用な解決策があることを願っています。事前に感謝します!

役に立ちましたか?

解決

リダイレクト ディレクティブは URLパスでのみ機能しますが、機能しませんURLのホストまたはクエリ。

しかし、 mod_rewrite で可能です:

RewriteCond %{HTTP_HOST} =example.org
RewriteCond %{QUERY_STRING} =id=1
RewriteRule ^default\.asp$ http://www.example.org/newpage.html [NC,L,R=301]

コメントで既に述べたように、 rewriteを使用できます。 IDからエイリアスへのマッピングのマップ

1 foo-page
2 bar-page
3 baz-page
…

RewriteMap 宣言(ここでは単純なプレーンテキストファイル):

RewriteMap id-to-alias txt:/absolute/file/system/path/to/id-to-alias.txt

そして最後にアプリケーション:

RewriteCond %{HTTP_HOST} =example.org
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)id=([0-9]+)&?([^&].*)?$
RewriteCond ${id-to-alias:%3}&%1%4 ^([^&]+)&(.*)
RewriteRule ^default\.asp$ http://www.example.org/%1.html?%2 [NC,L,R=301]

これは、残りのクエリも保持する必要があります。したくない場合:

RewriteCond %{HTTP_HOST} =example.org
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)id=([0-9]+)&?([^&].*)?$
RewriteCond ${id-to-alias:%3} .+
RewriteRule ^default\.asp$ http://www.example.org/%0.html? [NC,L,R=301]

他のヒント

mod_rewriteに代わる優れた方法は、最も使いやすい言語を使用して、スクリプトにロジックを配置することです。シンプルなフロントコントローラーにリダイレクトするすべてのURLを指定します。

RewriteRule ^default.asp$ /redirect.php [L]
RewriteRule ^another/path/to_some_file.ext$ /redirect.php [L]

そして、redirect.phpで:

<?php
if (

mod_rewriteに代わる優れた方法は、最も使いやすい言語を使用して、スクリプトにロジックを配置することです。シンプルなフロントコントローラーにリダイレクトするすべてのURLを指定します。

RewriteRule ^default.asp$ /redirect.php [L]
RewriteRule ^another/path/to_some_file.ext$ /redirect.php [L]

そして、redirect.phpで:

<*>SERVER['SCRIPT_URL'] == '/default.asp'){ $map = array( 1 => '/newpage.html', 2 => '/contact.html' ); if (isset(

mod_rewriteに代わる優れた方法は、最も使いやすい言語を使用して、スクリプトにロジックを配置することです。シンプルなフロントコントローラーにリダイレクトするすべてのURLを指定します。

RewriteRule ^default.asp$ /redirect.php [L]
RewriteRule ^another/path/to_some_file.ext$ /redirect.php [L]

そして、redirect.phpで:

<*>GET['id'])){ $id =

mod_rewriteに代わる優れた方法は、最も使いやすい言語を使用して、スクリプトにロジックを配置することです。シンプルなフロントコントローラーにリダイレクトするすべてのURLを指定します。

RewriteRule ^default.asp$ /redirect.php [L]
RewriteRule ^another/path/to_some_file.ext$ /redirect.php [L]

そして、redirect.phpで:

<*>GET['id']; if (isset($map[$id])){ header('HTTP/1.1 301 Moved Permanently', true, 301); header('Location: http://'.

mod_rewriteに代わる優れた方法は、最も使いやすい言語を使用して、スクリプトにロジックを配置することです。シンプルなフロントコントローラーにリダイレクトするすべてのURLを指定します。

RewriteRule ^default.asp$ /redirect.php [L]
RewriteRule ^another/path/to_some_file.ext$ /redirect.php [L]

そして、redirect.phpで:

<*>SERVER['HTTP_HOST'].$map[$id]); exit; } } } // ... handle another/path/to_some_file.ext here, or other domains, or whatever ... // If we get here, it's an invalid URL header('HTTP/1.1 404 Not Found', true, 404); echo '<h1>HTTP/1.1 404 Not Found</h1>'; echo '<p>The page you requested could not be found.</p>'; exit; ?>

情報を追加するだけ

OPのリダイレクトディレクティブはおそらく間違った形式です-関連するapacheドキュメントページ

  

リダイレクトディレクティブは古いURLをマップします   クライアントに   新しい場所でリソースを再取得します   場所。

     

古いURLパスでは大文字と小文字が区別されます   (%-decoded)パスで始まる   スラッシュ。相対パスは   許可された。新しいURLは   スキームで始まる絶対URL   およびホスト名。例:

Redirect /service http://foo2.bar.com/service

だからそれはそれをするでしょう:

Redirect 301 /default.asp?id=1 http://www.example.org/newpage.html

役立つこと

httpd.conf内:

RedirectPermananent URL1 URL2

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top