2

まず、これが私のディレクトリ構造です

/localhost/p/
  .htaccess
/localhost/p/inc/
  style.css

私はこのスニペットを持っています/localhost/p/.htaccess

Options -MultiViews +FollowSymLinks 
RewriteEngine On
RewriteBase /p/

RewriteCond %{REQUEST_FILENAME} ^(.+)/([^/]+)$
RewriteCond %1/inc/%2 -f
RewriteRule ([^/]+)$ inc/$1 [L]

RewriteRule ^(.+)$ index.php [QSA,L]

のファイルにはアクセスできませんlocalhost/p/style.cssが、index.php にはアクセスできます。

ここにログがあります

[perdir D:/p/] strip per-dir prefix: D:/p/style.css -> style.css
[perdir D:/p/] applying pattern '([^/]+)$' to uri 'style.css'
[perdir D:/p/] RewriteCond: input='D:/p/style.css' pattern='^(.+)/([^/]+)$' => matched
[perdir D:/p/] RewriteCond: input='D:/p/inc/style.css' pattern='-f' => matched
[perdir D:/p/] rewrite 'style.css' -> 'inc/style.css'
[perdir D:/p/] add per-dir prefix: inc/style.css -> D:/p/inc/style.css

// I don't know how to stop the .htaccess here, and just get the file
// instead go with [INTERNAL REDIRECT]

[perdir D:/p/] trying to replace prefix D:/p/ with /p/
strip matching prefix: D:/p/inc/style.css -> inc/style.css
add subst prefix: inc/style.css -> /p/inc/style.css
[perdir D:/p/] internal redirect with /p/inc/style.css [INTERNAL REDIRECT]
[perdir D:/p/] strip per-dir prefix: D:/p/inc/style.css -> inc/style.css
[perdir D:/p/] applying pattern '([^/]+)$' to uri 'inc/style.css'
[perdir D:/p/] RewriteCond: input='D:/p/inc/style.css' pattern='^(.+)/([^/]+)$' => matched
[perdir D:/p/] RewriteCond: input='D:/p/inc/inc/style.css' pattern='-f' => not-matched

// Of course it will never match, it should be D:/p/inc/style.css

...
...
...

ありがとう、

4

1 に答える 1

4

この RewriteCond を使用して、内部リダイレクトを 1 つだけ許可します。

## prevent looping from internal redirects
RewriteCond %{ENV:REDIRECT_STATUS} !200
于 2012-05-30T15:08:25.237 に答える