0

htaccess に関する質問がありますが、これは非常に単純で (ばかげていますか?)、これまで誰も質問する必要がなかったと思います。私はhtmlページの使用からphpに変換しましたが、ほとんどの場合、次のように機能しました:

<IfModule mod_rewrite.c>
 Options +FollowSymlinks
 RewriteEngine on
 RewriteRule ^(.+)\.htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
</IfModule>

ただし、いくつかの例外があるため、次のように仮定しました。

Redirect 301 /oldpage.htm http://example.com/newpage.php

IfMofule の上... トリックを行いますが、そうではありません。残りのコードを削除しない限り、「リダイレクト 301」は無視されます。誰かが私が間違っていることを教えてもらえますか?

ティア。

4

2 に答える 2

0

Apache は最初に mod_rewrite (Rewrite*) を処理し、次に mod_alias (リダイレクト) を処理します。

RewriteCond/oldpage.htm が mod_rewrite によって処理されないようにするために使用します。

RewriteCond %{REQUEST_URI} !^/oldpage\.htm$
RewriteRule ^(.+).htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]

またはRewriteRuleの代わりに使用しRedirectます。

RewriteRule ^oldpage\.htm$ http://example.com/newpage.php [L,R=301]
RewriteRule ^(.+).htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
于 2012-12-11T12:15:37.900 に答える
0

mod_rewrite と mod_alias を一緒に使用しており、両方とも同じ URL に適用されています。mod_rewrite または mod_alias のいずれかを使用する必要があります。

mod_rewrite: (Redirectディレクティブを削除)

<IfModule mod_rewrite.c>
 Options +FollowSymlinks
 RewriteEngine on
 RewriteRule ^oldpage.htm$ http://example.com/newpage.php [R=301,L]
 RewriteRule ^(.+)\.htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
</IfModule>

mod_alias: (<IfModule mod_rewrite.c>ブロック内のすべてを削除:

Options +FollowSymlinks
Redirect 301 /oldpage.htm http://example.com/newpage.php
RedirectMatch 301 ^/(.+)\.htm$ /htmlrewrite.php?page=$1
于 2012-12-11T12:15:46.927 に答える