如果时间太长,我提前致歉。我认为更多的细节总比少的要好,希望我不会被吓到了:-)
我在笔记本电脑上使用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
。 [我还没有在prod中继续这样做,但是我怀疑它也能正常工作。]但是,为了将它们结合在一起,我不得不将我的文档根目录从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
。
关于apache - 如何使用别名重写规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6533797/