【问题标题】:Query string url to seo friendly url查询字符串 url 到 seo 友好的 url
【发布时间】:2015-02-18 04:09:56
【问题描述】:

我正在尝试重写一个用于 SEO 的 URL。

旧网址是:

http://www.example.com/recipe_local.php?hl_cusine=1

新的 URL 应该像下面这样,如果用户超过 url,则自动重定向到这个 url

http://www.example.com/recipes/healthy-recipes

我在 .htaccess 中的代码是:

RewriteEngine on
RewriteRule ^recipes/healthy-recipes/$ recipe_local.php?hl_cusine=$1 [NC,L]
RewriteRule ^recipes/healthy-recipes$ recipe_local.php?hl_cusine=$1 [NC,L]

即使经过数小时的研究,我也不知道为什么这不起作用:(

【问题讨论】:

  • 你要去哪个网址,你希望看到什么?
  • healthy-recipes 怎么可以只在重写规则中变成hl_cusine=1
  • 您正试图立即做事(就像人们在这种情况下经常做的那样)。首先,您希望这样当用户输入http://www.example.com/recipes/healthy-recipes/42 时,它的行为就好像他们输入了http://www.example.com/recipe_local.php?hl_cusine=42(内部重写)。其次,使用完全不同的规则,您希望当用户实际输入http://www.example.com/recipe_local.php?hl_cusine=42 时,他们的浏览器被告知加载http://www.example.com/recipes/healthy-recipes/42(外部重定向)。

标签: php apache .htaccess url mod-rewrite


【解决方案1】:

您重写中的$1 指向您从未捕获的反向引用。
除非您有 RewriteCond,否则您不会显示?
试试:

RewriteEngine on
RewriteRule ^recipes/healthy-recipes/$ recipe_local.php?hl_cusine=1 [NC,L]
RewriteRule ^recipes/healthy-recipes$ recipe_local.php?hl_cusine=1 [NC,L]

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-31
  • 2012-09-27
  • 1970-01-01
  • 1970-01-01
  • 2011-08-13
  • 2014-12-03
  • 2014-09-23
相关资源
最近更新 更多