将URL段转换(重定向)为GET参数

时间:2017-08-18 14:51:53

标签: .htaccess url-redirection

我知道这可能已得到解答,但我找不到任何与我的问题有关的内容。

我有这样的网址:

https://staging.books.co.za/travelguide/route-map/SAFI546754
https://staging.books.co.za/travelguide/route-map/SAFI189444
https://staging.books.co.za/travelguide/route-map/SAFI978634

我需要将它们重定向到这样的URL:

https://staging.books.co.za/travelguide/route-map?reference=SAFI546754
https://staging.books.co.za/travelguide/route-map?reference=SAFI189444
https://staging.books.co.za/travelguide/route-map?reference=SAFI978634

请帮助......我的.htaccess文件中的规则是什么样的???

2 个答案:

答案 0 :(得分:1)

这应该可以解决问题:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^travelguide/route-map/(.+) /travelguide/route-map?reference=$1

请点击此处查看演示http://htaccess.mwl.be?share=6c2be57a-6bb7-5083-9122-aaf63162b240

答案 1 :(得分:0)

.htaccess

中尝试使用此功能
RewriteEngine On
RewriteRule ^travelguide/route-map/([-a-zA-Z0-9_]+)/?$ route-map?reference=$1 [L]

确保在测试之前清除缓存。