skip to Main Content

I have a URL which ends

/presentation/Item?k=ZW52aXJvbm1lbnRhbC1oZWFsdGgtc2FmZXR5LXNlY3VyaXR5LWVuZ2xpc2g=&

Which I need to redirect to http://domain.co.uk/films/ehss/

But when I use the following; it doesn’t work; I’ve tried escaping special characters like the ? by adding a before it but still no joy.

If its of any use this is all being added to the very beginning of htaccess file on a wordpress site.

This is what I’ve been trying:

Redirect 301 /presentation/Item?k=ZW52aXJvbm1lbnRhbC1oZWFsdGgtc2FmZXR5LXNlY3VyaXR5LWVuZ2xpc2g=& http://domain.co.uk/films/ehss/

I’ve looked into see if any of the other characters are special characters and they aren’t. Also, I don’t think I can use REGEX for this either as I have about 50 urls all in the same format as above that need to be redirected to seo friendly urls.

2

Answers


  1. You can parse QUERY_STRING using mod_rewrite

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} ^k=ZW52aXJvbm1lbnRhbC1oZWFsdGgtc2FmZXR5LXNlY3VyaXR5LWVuZ2xpc2g=&$ [NC]
    RewriteRule ^presentation/Item$ http://domain.co.uk/films/ehss/? [R=301,L]
    
    Login or Signup to reply.
  2. You cannot match query string using Redirect directive. You can use THE_REQUEST variable to match both request uri and query string like this:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} /presentation/Item?k=ZW52aXJvbm1lbnRhbC1oZWFsdGgtc2FmZXR5LXNlY3VyaXR5LWVuZ2xpc2g=& [NC]
    RewriteRule ^ /films/ehss/? [R=301,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search