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 回答