Apache 重写以将目录添加到 REQUEST_URI 在运行 wamp 的本地主机上不起作用

发布于 2024-08-25 23:38:20 字数 806 浏览 4 评论 0原文

我在 Vista (Apache v2.2.11) 上运行 wamp 并设置了项目,使得 http://localhost/projectxprojectx< 的基本目录/代码>。现在,我希望请求

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Spring初心 2024-09-01 23:38:20

尝试更改此:

RewriteRule ^(.*)$ /PUBLIC$1 [L]

对此:

RewriteRule ^(.*)$ PUBLIC$1 [L]

这可能只是绝对路径的问题。

您还需要将 $1 更改为从零开始,因此 RewriteRule ^(.*)$ PUBLIC$0 [L]

Try changing this:

RewriteRule ^(.*)$ /PUBLIC$1 [L]

To this:

RewriteRule ^(.*)$ PUBLIC$1 [L]

It's probably just the absolute path that is the problem.

You also need to change the $1 to be zero based so RewriteRule ^(.*)$ PUBLIC$0 [L]

苍景流年 2024-09-01 23:38:20

应该是

RewriteEngine On     
RewriteBase /projectx  
RewriteCond %{REQUEST_URI} !^/PUBLIC  
RewriteRule  ^(.*)(PUBLIC)(.*)$ /projectx/PUBLIC$3 [L]

Should be

RewriteEngine On     
RewriteBase /projectx  
RewriteCond %{REQUEST_URI} !^/PUBLIC  
RewriteRule  ^(.*)(PUBLIC)(.*)$ /projectx/PUBLIC$3 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文