3

私のmod_rewriteはうまく機能していますが、たとえば/calgary/の後に何も認識されません。

それで、私がに行って、それがindex.phpページ/calgary/login.phpだけを見ているならば?ページを認識しませんか?/login.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /city_name

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*)/?$ /city_name/index.php?page=$1 [L,QSA]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} /([^\./]+)\.php$
    RewriteCond %{DOCUMENT_ROOT}/city_name/%1.php -f
    RewriteRule ^(.*)/([^\./]+)\.php$ /city_name/?$2.php?page=$1 [L,QSA]
</IfModule>
4

2 に答える 2

1

You need to swap those 2 rules:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /city_name

    # This used to be the 2nd rule
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} /([^\./]+)\.php$
    RewriteCond %{DOCUMENT_ROOT}/city_name/%1.php -f
    # there used to be a "?" here, remove it ----v
    RewriteRule ^(.*)/([^\./]+)\.php$ /city_name/$2.php?page=$1 [L,QSA]

    # this used to be the first rule
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*)/?$ /city_name/index.php?page=$1 [L,QSA]
</IfModule>

The less restrictive rule (the one that matches (.*)/?$) will match /calgary/login.php outright before the second set of rules gets to do its thing, which seems to be rewritten to /city_name/?login.php?page=calgary.

Is that really what you want? There are two ? in the target there. Maybe you only want /city_name/$2.php?page=$1?

于 2012-08-29T19:12:02.480 に答える
0

最初の書き換えルールから「L」を削除してみてください。これにより、一致が見つかった場合、Apache はそれ以降のルールの処理を停止するようになります。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /city_name

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*)/?$ /city_name/index.php?page=$1 [QSA]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} /([^\./]+)\.php$
    RewriteCond %{DOCUMENT_ROOT}/city_name/%1.php -f
    RewriteRule ^(.*)/([^\./]+)\.php$ /city_name/?$2.php?page=$1 [L,QSA]
</IfModule>
于 2012-08-29T19:15:47.677 に答える