.htaccessでリダイレクトをしたいのですが、うまく反映されません。
Redirect permanent /example/db/foo.php?cid=160 http://www.example.net/aaa/
Redirect permanent /example/db/foo.php?cid=158 http://www.example.net/bbb/
Redirect permanent /example/db/foo.php?cid=157 http://www.example.net/ccc/
ちなみに、?を外すと反映されています。
Redirect permanent /example/db/viewcat.php http://www.example.net/aaa/
そのものズバリのコードをご教授ください。
よろしくお願いします。
RewriteEngine on RewriteCond %{QUERY_STRING} ^cid=(.*)&(.*)$ RewriteRule ^example/db/foo.php(.*)$ http://www.example.net/example/db/foo.php/cid/%1/%2? RewriteCond %{QUERY_STRING} ^cid=(.*)$ RewriteRule ^example/db/foo.php(.*)$ http://www.example.net/example/db/foo.php/cid/%1? RewriteRule example/db/foo.php/cid/160 http://www.example.net/aaa/ RewriteRule example/db/foo.php/cid/158 http://www.example.net/bbb/ RewriteRule example/db/foo.php/cid/159/123 http://www.example.net/ccc/
このようなコードで実現できます。
RewriteCondの部分で、
http://www.example.net/example/db/foo.php/cid/160
http://www.example.net/example/db/foo.php/cid/158
http://www.example.net/example/db/foo.php/cid/159/123
などに変換しています。
そのあと、Redirect permanentではありませんが、RewriteRuleで個別にリダイレクト先を指定しております。
ただ、結局のところ、
RewriteRule example/db/foo.php/cid/160 http://www.example.net/aaa/
のように、cidに対応してリダイレクト先を決める部分は、70ページ部分書く必要がありますので、そこはがんばってください
RedirectMatch permanent /example/db/foo.php?cid=160 http://www.example.net/aaa/
RedirectMatch permanent /example/db/foo.php?cid=158 http://www.example.net/bbb/
RedirectMatch permanent /example/db/foo.php?cid=157 http://www.example.net/ccc/
としましたが、反映されませんでした。
RedirectMatchでリダイレクトされるコードをご教授いただけますでしょうか?
Redirect permanentや RedirectMatch permanent は、クエリ文字列に対応してないので、mod_rewriteを使うことになります。
コードとしては、↓のような感じで
RewriteEngine on RewriteCond %{QUERY_STRING} "cid=160" RewriteCond %{REQUEST_URI} "/db/foo.php" RewriteRule ^(.*)$ http://www.example.net/aaa/ RewriteCond %{QUERY_STRING} "cid=158" RewriteCond %{REQUEST_URI} "/db/foo.php" RewriteRule ^(.*)$ http://www.example.net/bbb/ RewriteCond %{QUERY_STRING} "cid=157" RewriteCond %{REQUEST_URI} "/db/foo.php" RewriteRule ^(.*)$ http://www.example.net/ccc/
ありがとうございます。
リダイレクトが必要なページが70ほどあり、一つづつするにはかなり労力が必要で。。
あと、その後に&もあり、これも含めて処理をする必要があるのですが
たとえば、
http://www.example.net/example/db/foo.php?cid=160
http://www.example.net/example/db/foo.php?cid=158
http://www.example.net/example/db/foo.php?cid=159&123
となっているものを
http://www.example.net/example/db/foo.php/cid/160
http://www.example.net/example/db/foo.php/cid/158
http://www.example.net/example/db/foo.php/cid/159/123
のように一括してRewrite後
Redirect permanent /example/db/foo.php/cid/160 http://www.example.net/aaa/
Redirect permanent /example/db/foo.php/cid/158 http://www.example.net/bbb/
Redirect permanent /example/db/foo.php/cid/159/123 http://www.example.net/ccc/
としたRedirectってできるのでしょうか?
可能であれば、度々で申し訳ないのですがそのRewriteのコードをご教授いただけますでしょうか?
RewriteEngine on RewriteCond %{QUERY_STRING} ^cid=(.*)&(.*)$ RewriteRule ^example/db/foo.php(.*)$ http://www.example.net/example/db/foo.php/cid/%1/%2? RewriteCond %{QUERY_STRING} ^cid=(.*)$ RewriteRule ^example/db/foo.php(.*)$ http://www.example.net/example/db/foo.php/cid/%1? RewriteRule example/db/foo.php/cid/160 http://www.example.net/aaa/ RewriteRule example/db/foo.php/cid/158 http://www.example.net/bbb/ RewriteRule example/db/foo.php/cid/159/123 http://www.example.net/ccc/
このようなコードで実現できます。
RewriteCondの部分で、
http://www.example.net/example/db/foo.php/cid/160
http://www.example.net/example/db/foo.php/cid/158
http://www.example.net/example/db/foo.php/cid/159/123
などに変換しています。
そのあと、Redirect permanentではありませんが、RewriteRuleで個別にリダイレクト先を指定しております。
ただ、結局のところ、
RewriteRule example/db/foo.php/cid/160 http://www.example.net/aaa/
のように、cidに対応してリダイレクト先を決める部分は、70ページ部分書く必要がありますので、そこはがんばってください
カンペキです。ありがとうございます。
>cidに対応してリダイレクト先を決める部分は、70ページ部分書く必要がありますので、そこはがんばってください
やりますやります、全然やります。m(__)m
助かりました。m(__)m
カンペキです。ありがとうございます。
>cidに対応してリダイレクト先を決める部分は、70ページ部分書く必要がありますので、そこはがんばってください
やりますやります、全然やります。m(__)m
助かりました。m(__)m