Transform(redirect) URL segment to a GET parameter

2019-06-10 19:39发布

问题:

I know this has probably been answered but I can't find anything specific to my issue.

I have URLS like this:

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

and I need them to be redirected to URLS like this:

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

Please help...What would the rule look like in my .htaccess file???

回答1:

This should do the trick:

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

See here for a demo http://htaccess.mwl.be?share=6c2be57a-6bb7-5083-9122-aaf63162b240



回答2:

Try and use this in your .htaccess:

RewriteEngine On
RewriteRule ^travelguide/route-map/([-a-zA-Z0-9_]+)/?$ route-map?reference=$1 [L]

Make sure you clear your cache before testing this.