0

新しいURL構造を持つwww.wildchildclothes.comの再設計を行いました。古いサイトはZenCartで実行されていて、URL構造が正しくありませんでした。これが私がリダイレクトしたいもののいくつかの例です:

古い:www.wildchildclothes.com/page.html?chapter=1&id=21新しい:www.wildchildclothes.com

と...

古い:www.wildchildclothes.com/index.php?main_page=faq_info&fcPath=0&faqs_id=13新しい:www.wildchildclothes.com/customer-service.html

これを達成するために私の.htaccessにあるものは次のとおりです。

RewriteEngine On
RewriteBase / 
RewriteCond %{QUERY_STRING} ^([^&]*&)*chapter=1(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*id=21(&|$)
RewriteRule ^page\.html http://www.wildchildclothes.com? [L,R=301]
RewriteCond %{QUERY_STRING} ^([^&]*&)*main_page=faq_info(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*fcPath=0(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*faqs_id=13(&|$)
RewriteRule ^index\.php$ http://www.wildchildclothes.com/customer-service.html? [L,R=301]

しかし、これはまったく機能しません。リダイレクトを開始するのではなく、404ページにのみ送信されます。誰かが光を当てることができますか?完全な.htaccessは以下に掲載されています。

どうもありがとう、ジョナ

4

3 に答える 3

2

上記の解決策はどれも私にはうまくいきませんでしたが、これはうまくいきます:

www.wildchildclothes.com/page.html?chapter=1&id=21をwww.wildchildclothes.comにリダイレクトするには:

RewriteCond %{query_string} chapter=1&id=21
RewriteRule (.*) http://www.wildchildclothes.com/? [R=301,L]

www.wildchildclothes.com/index.php?main_page=document_product_info&products_id=280をwww.wildchildclothes.comにリダイレクトするには:

RewriteCond %{query_string} main_page=document_product_info&products_id=280
RewriteRule (.*) http://www.wildchildclothes.com/? [R=301,L]

www.wildchildclothes.com/index.php?main_page=faq_info&fcPath=0&faqs_id=9をwww.wildchildclothes.com/customer-service.htmlにリダイレクトするには:

RewriteCond %{query_string} main_page=faq_info&fcPath=0&faqs_id=9
RewriteRule (.*) http://www.wildchildclothes.com/customer-service.html? [R=301,L]

これを行うにはもっと良い方法があると確信していますが、これは私にとってはうまくいき、.htaccessは私に頭痛の種を与えるだけなので、これ以上掘り下げることはしません。

これが他の誰かに役立つことを願っています!

  • ジョナ
于 2009-11-22T23:40:59.843 に答える
0

リダイレクトにPHPを使用すると、より簡単ではるかに優れたものになります。たとえば、このようなリクエストを、URL引数を分析して正しいページにリダイレクトするPHPスクリプトに書き換えることができます。多分このようなもの:

// old-to-new.php
$rules = array(
    array(
        array('chapter' => '0', 'id' => '23'),  // old URL parameters
        '/customer-service.html'                // new URL
    ),
    // …
);
foreach ($rules as $rule) {
    if (array_intersect_assoc($rule[0], $_GET) == $rule[0]) {
        header('Location: http://example.com'.$rule[1], true, 301);
        exit;
    }
}
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
exit;

そして対応するRewriteRule

RewriteRule ^page\.html$ old-to-new.php [L]
于 2009-11-12T17:27:36.633 に答える
0

クエリパラメータに複数の文字を許可する必要があります。[^&]&に変更[^&]*&

RewriteCond %{QUERY_STRING} ^([^&]*&)*chapter=1(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*id=21(&|$)
RewriteRule ^page\.html$ http://www.wildchildclothes.com? [L,R=301]

RewriteCond %{QUERY_STRING} ^([^&]*&)*main_page=faq_info(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*fcPath=0(&|$)
RewriteCond %{QUERY_STRING} ^([^&]*&)*faqs_id=12(&|$)
RewriteRule ^index\.php$ http://www.wildchildclothes.com? [L,R=301]
于 2009-11-12T19:04:36.847 に答える