我不能让rewriterule工作

时间:2012-02-28 12:03:30

标签: apache mod-rewrite localhost url-rewrite-module

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

启用了重写模块,我使用alice.html和bob.html示例对其进行了测试 (http://stackoverflow.com/questions/6944521/url-rewriting-on-localhost) 它适用于www-subfolder中的.htacces。我还把垃圾文本放在.htaccess和.htaccess中 我从Apcheserver得到错误,所以重写mod正在运行,我驾驶室使用规则。

here is the rule: (inside /www/folder1/.htaccess)
Options +FollowSymLinks 
RewriteEngine  On
RewriteRule /(.*) /index.php?disp=$1 [QSA,L]

所以当我把这个url放到浏览器中时,我的索引页面加载好了。 http://localhost:8080/folder1/index.php

问题在于:当我通过index.page(登录页面)请求登录并将url发送到localhost时 服务器通过cliking发送按钮 网址改为localhost:8080 / login,应该是localhost:8080 / folder1 / login

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

我希望像这样转换网址:www.best-food-of-the-usa.com/index.php?operation=top&state=arizona& 城市=台面&安培;限制= 10

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

感谢任何帮助。谢谢 \圣何塞

1 个答案:

答案 0 :(得分:1)

RewriteRule的行为就像文档所说的那样。

来自RewriteRule Directive Apache Docs

  

匹配什么?

     

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

     

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

     

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

因此,在Directory and htaccess上下文中,前缀/www/folder1/将被删除。另请注意,在RewriteRule上下文中与Directory and htaccess匹配时,该模式永远不会以/开头。

所以,你的RewriteRule应该是:

Options +FollowSymLinks 
RewriteEngine  On
RewriteRule (.*) /index.php?disp=$1 [QSA,L]