Converting (redirecting) a URL segment to a GET parameter

I know this is probably answered, but I can not find anything specific in my problem.

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 as follows:

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 in my .htaccess file look like ???

0
source share
2 answers

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

+1
source

Try using it in .htaccess:

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

Before testing, make sure you clear the cache.

0
source

All Articles