且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

的.htaccess重写GET变量W / 301重定向

更新时间:2023-10-21 16:38:04

您希望这样的事情在你的htaccess文件:

You want something like this in your htaccess file:

RewriteRule ^locations/zip/([0-9]+)$ /locations/?zip=$1 [L,QSA]

这将使它所以当有人请求 http://www.domain.com/locations/zip/10001 ,他们将得到服务 /locations.php?zip=10001 。

This will make it so when someone requests http://www.domain.com/locations/zip/10001, they will get served the contents of /locations.php?zip=10001.

要重定向的旧网址到新的,你还需要添加:

To redirect the old URLs to the new ones, you will need to also add:

RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /locations(\.asp)?/?\?zip=([0-9]+)&?([^\ ]*)
RewriteRule ^ /locations/zip/%3?%4 [L,R=301]

所以,当有人试图去 http://www.domain.com/locations.asp?zip=10001 http://www.domain.com/locations/?zip=10001 ,他们重定向到 http://www.domain.com/locations/ ZIP / 10001

So when someone tries to go to http://www.domain.com/locations.asp?zip=10001 or http://www.domain.com/locations/?zip=10001, they get redirected to http://www.domain.com/locations/zip/10001.