2

学校の机に戻る必要があるか、何か変なことが起こっているかのどちらかです。

実際の物理ファイルとディレクトリが解決されないため、次は機能しません。

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-l

  # The following rule must not affect real physical files, but does
  RewriteRule ^(img/.*)$ http://old.site.com/$1 [L,R=301]

  RewriteRule .* index.php [L]
</IfModule>

ただし、このコードは機能し、実際のファイルとフォルダーを問題なく解決します。

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-l

  RewriteRule ^(img/.*)$ http://old.site.com/$1 [L,R=301]

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-l

  RewriteRule .* index.php [L]
</IfModule>

すべての RewriteRule の前に新しい RewriteCond が本当に必要ですか?

4

2 に答える 2

6

RewriteCond は、次の RewriteRule にのみ適用されます。そうです、あなたの場合、すべての RewriteRule の前に RewriteCond が必要になります。

しかし、良いニュースは、それを回避できるということです。

これらの複数の RewriteCond を記述したくない場合は、次のコードで行うことができます。

## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]

RewriteRule ^(img/.*)$ http://old.site.com/$1 [L,R=301]

RewriteRule .* index.php [L]
于 2013-07-23T09:46:53.563 に答える
3

はい。

RewriteRule1 つの (セットの) に基づいて 2 つの を使用することはできませんRewriteCond

マニュアルからの引用:

Each rule can have an unlimited number of attached rule conditions...

One or more RewriteCond can precede a RewriteRule directive...

The RewriteRule directive [...] can occur more than once, with each instance defining a single rewrite rule...

于 2013-07-23T09:45:45.390 に答える