1

プロジェクトを開発するために、開発マシンでWampを使用しています。これは私の.htaccessです:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L] 
RewriteBase /project/

これはlocalhost/projectに配置されるため、localhost / project/somethingなどのリクエストはすべてlocalhost/project / index.php/somethingにルーティングされます。

ただし、それらはlocalhost / index.php/somethingにルーティングされています

RewriteBaseの使い方と関係があるのではないかと思います。どうすれば修正できますか?

4

2 に答える 2

3

You need to remove the leading slash in your rule:

# no slash---------v
RewriteRule ^(.*)$ index.php?$1 [L] 

Apache kind of guesses whether the targets of a RewriteRule is a URL-path or a file-path. When it starts with a slash, it assumes it's a URL-path and that it's absolute, so it'll go to the document root's index.php. Without the slash, it'll either guess a file-path or use the rewrite base to help determine which to use.

You should also move the RewriteBase directive above your rule.

于 2012-08-08T18:06:02.300 に答える
1

ベースをリライタルールに入れてみませんか?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /project/index.php?$1 [L] 

編集:

この質問が役立つかもしれません: htaccess RewriteBase

于 2012-08-08T13:32:01.383 に答える