如果时间太长,我事先表示歉意。我认为更多细节总比少要好,希望我不会被吓到了:-)
我在笔记本电脑上使用WAMP进行本地开发,并且我拥有各种c:/wamp/alias/*
文件,每个文件都指向项目工作目录。我获得了一些出色的mod_rewrite帮助,并获得了
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\/)?ih(\/.*)?$ $1index.php$2 [L,QSA]
用于将SEO友好且简短的URL的localhost/.../ih/sub/dir
更改为localhost/.../index.php/sub/dir
。 [我还没有在产品中继续这样做,但我怀疑它也能正常工作。]但是,为了将它们结合在一起,我不得不将我的文档根目录从c:/wamp/www/
更改为c:/
,确实宁愿不要这样做,以防万一我的Apache被黑了,否则是因为这太麻烦了。
我的测试别名文件看起来像
Alias /testme "c:/var/tmp/wamp-testme/"
<Directory "c:/var/tmp/wamp-testme/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\/)?ih(\/.*)?$ $1index.php$2 [L,QSA]
</Directory>
并且尝试加载http://localhost/testme/rewrites/ih/sub/path
时遇到的错误是
[Thu Jun 30 06:46:13 2011] [error] [client 127.0.0.1]
File does not exist: C:/wamp/www/var
具有匹配项
Not Found
The requested URL /var/tmp/wamp-testme/rewrites/index.php/sub/path
was not found on this server.
在浏览器中。果然,我的c:/wamp/alias/flying.conf
文件中指向c:/data/flying/
目录的同一配置将在错误日志文件中抛出File does not exist: C:/wamp/www/data
,依此类推。
Sooooo ...我如何拥有一个超越别名的重写规则,而我的文档根目录不在我的计算机根目录下?
[奇数:尝试在重写规则中添加PT
标志:这将强制将重写的URL发送回URL映射引擎。
编辑:尝试在目录上设置RewriteBase
。