0

1、2 日経っても、まだ Mod Rewrite と戦っています。私の開発時間の 60% はサーバーとの戦いに費やされているようです。

私の現在の URL 構造は、すべてのhttp://example.com/xyzhttp://example.com/xyz/abcが index.php によって処理されるようになっています。問題は、http://example.com/admin/セクションがあることです。これは、HTTP 要求を介してアクセスできるようにする必要がある実際のディレクトリです (CMS ディレクトリです)。

CMS http://example.com/admin/を参照しようとすると、URL がhttp://example.com/admin/?n=adminに変更され、404 が返されます。 =admin 引数として。

私が理解できないのは、これらの 2 つの条件が無視されている理由です。

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^admin(?:\/)?$

そして、なぜ http://example.com/admin/?n=admin にリダイレクトされるのですか(単にhttp://example.com/admin/で停止するのではなく.

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^admin(?:\/)?$

# allow access to certain subdirectories.
RewriteRule ^admin(?:\/)?$ /admin/ [L,NC]

# redirect all old URLs to new pages (or 404 sitemap page if no analog?).
RewriteRule ^company/about(?:\/)?$ /company [R=301,L,NC]

# catch any others and try to serve them right
RewriteRule ^/?(.+).html$ /$1 [R=301,L]

RewriteRule ^/?([0-9]+)(?:\/)?$ /index.php?p=$1 [L]
RewriteRule ^/?([-a-zA-Z0-9_+]+)(?:\/)?$ /index.php?n=$1 [L]
RewriteRule ^/?([-a-zA-Z0-9_+]+)/([-a-zA-Z0-9_+]+)(?:\/)?$ /index.php?n=$2 [L]

誰かアイデアを提供したり、.htaccess の欠陥を指摘したりできますか?

4

2 に答える 2

0

各RewriteCondは、次のRewriteRuleのみを適用します。

したがって、最初のルールのみに条件があります。

あなたのオプションは、ルールを繰り返すか、それから最後にして終了することです(私の頭からこれのフラグを思い出せません)

于 2009-11-19T08:06:32.760 に答える
0

Try this rule before your other rules:

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

This will end the rewrite process if the requested path can be mapped to an existing directory. The same applies when using -f instead.

于 2009-11-19T12:30:01.973 に答える