【问题标题】:.htaccess rule does rewrite URL in address bar.htaccess 规则会重写地址栏中的 URL
【发布时间】:2013-02-15 21:24:21
【问题描述】:

我有一个网站,我的链接看起来像这样 http://www.domain.com/index.php?lang=English&inc=canyoning 我设法像这样编写 rewriteRule:

RewriteRule (German|English)\/(.*) http://www.domain.com/index.php?lang=$1&inc=$2 [NC,R]

现在我的链接看起来像这样:<a href="http://www.domain.com/English/canyoning">...

这可行,但我可以在浏览器地址栏中看到非用户友好的 URL。如何告诉浏览器在 URL 中使用 /English/canyoning 之类的链接而不是 index.php?lang=English&inc=canyoning

第二:我想在页面上使用表单。 没有区别,无论我使用表单方法=GET还是POST,都没有变量到达目标站点。

我猜我的 rewriteRule 错误。如何解决这些问题?

感谢您的帮助!

【问题讨论】:

  • 您应该单独提出第二个问题。 StackOverflow 的常见问题解答格式不适用于多个问题。
  • 另外,您可能会在webmasters.stackexchange.com得到更好的回复

标签: php apache .htaccess mod-rewrite post


【解决方案1】:

这是因为您正在执行重定向而不是重写..(R 标志表示 Redirect

所以删除 R 标志应该可以解决您的问题。

您可能还需要删除硬编码域。当您进行重写时,您不能重写到不同的域。

即。改变

RewriteRule (German|English)\/(.*) http://www.domain.com/index.php?lang=$1&inc=$2 [NC,R]

RewriteRule (German|English)\/(.*) /index.php?lang=$1&inc=$2 [NC]

【讨论】:

  • 谢谢@cowls,这真的很有帮助!
猜你喜欢
  • 1970-01-01
  • 2011-12-06
  • 2016-11-19
  • 1970-01-01
  • 1970-01-01
  • 2012-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多