Apache 重写以将目录添加到 REQUEST_URI 在运行 wamp 的本地主机上不起作用
我在 Vista (Apache v2.2.11) 上运行 wamp
并设置了项目,使得 http://localhost/projectx
是 projectx< 的基本目录/代码>。现在,我希望请求
http://localhost/projectx/somepage/extra
将重写为
http://localhost/projectx/PUBLIC/somepage/extra
为此,我在 C:\wamp\www\projectx\.htacces
中有一个文件,就是这么简单:
RewriteEngine On
RewriteBase /projectx
RewriteCond %{REQUEST_URI} !^/PUBLIC
RewriteRule ^(.*)$ /PUBLIC$1 [L]
我不能为我的生活弄清楚为什么这不起作用。我收到的错误是“在此服务器上找不到请求的 URL /PUBLIC”。谢谢。
2010 年 3 月 25 日更新:
根据 Michael 的解决方案,我删除了绝对路径。由于某种原因,我还需要在条件和规则中添加最后一个斜杠:
RewriteEngine On
RewriteBase /projectx
RewriteCond %{REQUEST_URI} !^/PUBLIC/
RewriteRule ^(.*)$ PUBLIC/$1 [L]
I'm running wamp
on Vista (Apache v2.2.11) and have projects setup such that http://localhost/projectx
is the base directory for projectx
. Now, I want that requests for
http://localhost/projectx/somepage/extra
will rewrite to
http://localhost/projectx/PUBLIC/somepage/extra
To that end I have a file in C:\wamp\www\projectx\.htacces
that is this simple:
RewriteEngine On
RewriteBase /projectx
RewriteCond %{REQUEST_URI} !^/PUBLIC
RewriteRule ^(.*)$ /PUBLIC$1 [L]
I can't for the life of me figure out why this doesn't work. The error I'm getting is "The requested URL /PUBLIC was not found on this server". Thanks.
UPDATE 25-MAR-2010:
As per Michael's solution I removed the absolute path. For some reason I also needed to add a final slash to the Cond and Rule:
RewriteEngine On
RewriteBase /projectx
RewriteCond %{REQUEST_URI} !^/PUBLIC/
RewriteRule ^(.*)$ PUBLIC/$1 [L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试更改此:
对此:
这可能只是绝对路径的问题。
您还需要将
$1
更改为从零开始,因此RewriteRule ^(.*)$ PUBLIC$0 [L]
Try changing this:
To this:
It's probably just the absolute path that is the problem.
You also need to change the
$1
to be zero based soRewriteRule ^(.*)$ PUBLIC$0 [L]
应该是
Should be