.htaccess将单个查询字符串重定向到特定URL

时间:2013-10-05 14:42:52

标签: php regex apache .htaccess mod-rewrite

非常感谢 - 我正在扩展我对.htaccess的理解,但我在这里遇到了麻烦。情况是:

    /people.php forwards to /people

我想转发

    /people.php?id=1 to /people/james-doe
    /people.php?id=32 to /people/lucy-brown

等等 -

但不出所料我得到的是:

    /people/id=1

现在我确信有一个优雅的解决方案 - 任何人都可以提供任何帮助吗?

1 个答案:

答案 0 :(得分:1)

启用mod_rewrite.htaccesshttpd.conf,然后将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)id=1(&|$) [NC]
RewriteRule ^people\.php$ /people/james-doe? [R=301,L,NC]

RewriteCond %{QUERY_STRING} (^|&)id=32(&|$) [NC]
RewriteRule ^people\.php$ /people/lucy-brown? [R=301,L,NC]