简体   繁体   English

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

[英].htaccess redirect individual query string to specific url

Help much appreciated - i am extending my understanding of .htaccess but am having real trouble here. 非常感谢您的帮助-我扩展了对.htaccess的理解,但是在这里遇到了真正的麻烦。 The situation is: 情况是:

    /people.php forwards to /people

I want to forward 我想转发

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

and so on - 等等 -

but unsurprisingly what i get is: 但毫不奇怪,我得到的是:

    /people/id=1

Now I am sure there is an elegant solution to this - can anyone offer any help? 现在,我敢肯定有一个优雅的解决方案-有人可以提供任何帮助吗?

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file: 通过httpd.conf启用mod_rewrite.htaccess ,然后将此代码放入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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM