-1

我在笔记本电脑(本地主机:8080)上使用 VertrigoServ 2.27。

重写模块已启用,我使用 alice.html 和 bob.html 示例(http://stackoverflow.com/questions/6944521/url-rewriting-on-localhost)对其进行了测试,它与 www-subfolder 中的 .htacces 一起使用。而且我还在 .htaccess 中放入了垃圾文本,我从 Apcheserver 收到错误,所以 rewrite mod 正在运行并且我使用规则。

这是规则:(在/www/folder1/.htaccess 中)
选项 +FollowSymLinks
重写引擎开启
RewriteRule /(.*) /index.php?disp=$1 [QSA,L]

因此,当我将此 url 放入浏览器时,我的索引页面加载正常。 http://localhost:8080/folder1/index.php

问题就在这里:当我通过 index.page(login page) 请求登录并通过单击发送按钮将 url 发送到 localhost 服务器时,url 更改为 localhost:8080/login,它应该是 localhost:8080/folder1/login

  • 如何在 url 中保留子文件夹名称?

我想像这样转换网址:www.best-food-of-the-usa.com/index.php?operation=top&state=arizona& city=mesa&limit=10

喜欢这个:www.best-food-of-the-usa.com/arizona/mesa/top10.html

任何帮助表示赞赏。谢谢\何塞

4

1 回答 1

1

RewriteRule正如文档所说的那样。

来自RewriteRule Directive Apache Docs

什么是匹配的?

在 VirtualHost 上下文中,Pattern 最初将与 URL 的主机名和端口之后以及查询字符串之前的部分进行匹配(例如“/app1/index.html”)。

在 Directory 和 htaccess 上下文中,模式最初将与文件系统路径匹配,在删除引导服务器到当前 RewriteRule 的前缀之后(例如“app1/index.html”或“index.html”,具体取决于指令的位置定义)。

如果您希望匹配主机名、端口或查询字符串,请分别使用带有 %{HTTP_HOST}、%{SERVER_PORT} 或 %{QUERY_STRING} 变量的 RewriteCond。

因此,在Directory and htaccess上下文中,前缀/www/folder1/将被删除。还要记住RewriteRuleDirectory and htaccess上下文中匹配 with 时,模式永远不会以/.

所以,你RewriteRule应该是:

Options +FollowSymLinks 
RewriteEngine  On
RewriteRule (.*) /index.php?disp=$1 [QSA,L]
于 2012-02-28T12:56:33.360 回答