【发布时间】: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