1
votes

I have some URLs generated by a CMS (SilverStripe CMS) that I wish to rewrite. For some reason it's possible to set a URL like by appending a ?url= to the query string.

So example.com?url=/about-us and example.com/about-us gives the same page.
You can even do example.com/some-page/?url=/about-us and you will still get the about us page.

So: How do I rewrite any URL that contains the parameter "url" into domain.tld + the value of the URL paramater? (example.com?url=/about-us and example.com/some-page/?url=/about-us and so on into example.com/about-us).

Hope someone can help.

1

1 Answers

0
votes

Try adding these rules to the htaccess file in your document root:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^\?]*\?url=([^&\ ]+)&?([^\ ]*)
RewriteRule ^ /%1?%2 [L,R=301]

This will take any request with a url=<something> query string param, completely ignore the URI, and redirect the browser to /<something> and append whatever query string happens to be after.