简体   繁体   English

如何使用.htaccess文件永久重定向网址?

[英]How to permanently redirect a url with a .htaccess file?

I need to do a 301 permanent redirect from 我需要从进行301永久重定向

http://www.example.com/search.php?search=samplesearch

to

http://www.example.com/used/search.php?search=samplesearch [301]

Any help greatly appreciated. 任何帮助,不胜感激。 Thanks 谢谢

I think you'll find your answer if you search stackoverflow for ' redirect htaccess 301 '. 我认为,如果您在stackoverflow中搜索“ redirect htaccess 301 ”,将会找到答案。 If you want to see how it's done. 如果您想看看它是如何完成的。 Use your cPanel to create a permanent redirect and then open your htaccess file with a text editor or cpanel filemanager to view the code. 使用cPanel创建永久重定向,然后使用文本编辑器或cpanel filemanager打开htaccess文件以查看代码。 Then you'll know how to mod the htaccess manually if you need to. 然后,您将知道如何根据需要手动修改htaccess。

Use RewriteCond with %{THE_REQUEST} 将RewriteCond与%{THE_REQUEST}一起使用

RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET \/search\.php\?search=samplesearch\ HTTP/ [NC]
RewriteRule ^(.*)$ /used/search.php?search=samplesearch [R=301,L]

For more information about mod_rewrite variables this site may help you: http://www.askapache.com/tools/mod_rewrite-variables-cheatsheet.html 有关mod_rewrite变量的更多信息,此站点可能会帮助您: http : //www.askapache.com/tools/mod_rewrite-variables-cheatsheet.html

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

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