1

過去 3 日間、私は Apache の mod_rewrite をいじって、URL から index.php を削除しようとしましたが、php はまだパスでそれを確認する必要があります。

Essentially PHP needs to see this
http://example.com/index.php/Page/Param1/Param2

While the user needs to see this
http://example.com/Page/Param1/Param2

私が今持っているのは、htaccessファイルの次のとおりです

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]

これは別のページから取得したもので、必要なものに近いものです。http://example.com/しかし、これはパートの後のすべてを切り取っているようです。mod_rewrite でユーザーに 1 つのものを表示し、php に別のものを表示するにはどうすればよいですか?

4

2 に答える 2

1

これは、URI から index.php を削除するために .htaccess (DOCUMENT_ROOT の下) で使用できる変更されたコードです。

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (?!^index\.php)^(.+)$ /index.php/$1 [L,NC]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php(/[^\s\?]+)? [NC]
RewriteRule ^ %1%2 [R=302,L]

R=302 を R=301 に変更して、問題なく動作していることを確認してください。

于 2012-07-20T03:39:01.160 に答える
1

このルール:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]

次のようにする必要があります。

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /index\.php(.*)\  [NC]
RewriteRule ^ /%1 [R=301,L]

RewriteRule ^(.*)$ index.php?$1 [L,QSA]また、 は次のような URI を作成せず、次のような/index.php/Page/Param1/Param2クエリ文字列を作成することに注意してください/index.php?Page/Param1/Param2。これは、PHPが見る必要があると言ったものとはまったく異なります。

于 2012-07-20T01:08:51.327 に答える