查询字符串网址到seo友好网址

时间:2015-02-18 04:09:57

标签: php apache .htaccess url mod-rewrite

我正在尝试为SEO目的重写URL。

旧网址为:

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

如果用户来到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]

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

1 个答案:

答案 0 :(得分: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]