从的.htaccess GET变量重定向到URL字符串 [英] .htaccess redirect from GET variable to url string
问题描述
我需要重定向
/search?keywords=somesearchterm
到
/search/somesearchterm
这似乎令人难以置信的基本的,但我一直在敲打我的头靠在了一个小时。
This seems incredibly basic but I've been pounding my head against it for an hour.
感谢您抽出时间来看看这个。
Thanks for taking the time to look at this.
推荐答案
您想实现什么是所谓的301重定向与mod_rewrite的。
You want to implement what is called a "301 Redirect" with mod_rewrite.
RewriteEngine ON
RewriteRule ^/search\?keywords=somesearchterm$ /search/somesearchterm
补充定期EX pressions:
adding regular expressions:
RewriteEngine ON
RewriteRule ^/search\?keywords=(.+) /search/$1 [R=301,L]
R = 301
表示提供301头重定向,以便在浏览器用户的URL发生变化,而→
办法不处理任何更多的重写规则,如果此匹配。
R=301
means provide a 301 Header redirect so the user's URL changes in the browser, and L
means don't process any more rewrite rules if this one matches.
如果你想要做相反的 - 换句话说,如果有人去 mysite.com/search/asearchterm
和您想要的网址保持不变,但幕后你想让它加载某些服务器脚本,做到这一点:
If you want to do the reverse -- in other words, if someone goes to mysite.com/search/asearchterm
and you want the URL to stay the same, but "behind the scenes" you want it to load a certain server script, do this:
RewriteEngine ON
RewriteRule ^/search/(.+) /search.php\?keywords=$1 [L]
这篇关于从的.htaccess GET变量重定向到URL字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!