Ad

Redirect Url With Query String To Ca Certain Page

- 1 answer

i have URLs which look like this: https://domain.de/immobilien?bis-kaltmiete&info-message=test&vermarktungsart=miete&von-kaltmiete&callback=confirm_searchagent&confirm=1aa46e80c4d57ef40a6ddab59cf5aebd#flash-message

Now i want to redirect URLs with the certain query "callback=confirm_searchagent". I tryed to do this via .htaccess and used the following code

 RewriteCond %{QUERY_STRING} ^callback=(.*)$
 RewriteRule ^(.*)$ /immobilien/ [R=301,L]

The code did not change anything, no redirection, no errors.

i hope somebody can help me with this?

Ad

Answer

You can use this :

 RewriteCond %{QUERY_STRING} callback=(.*)
 RewriteRule ^(.*)$ /immobilien/? [R=301,L]

I removed the ^ from your condition regex as it was looking for a query string that starts with this spacific key. Also I added a ? at the end of the rule to remove query strings from the new redirected URL. You can remove this ? if you want query string appended.

Ad
source: stackoverflow.com
Ad