1

I'm trying to redirect URLs with a half of MD5 part inside a PHP query and one base64 encoded string after a '#' symbol to a new directory using a .htaccess Rewrite Rule.

URL examples:

A) /?7027fcbbc2a1ccb9#N61/vMSRNqYQBhb+DcaSfv2YGW1HiBbSpMUoSHrtxok=

B) /index.php?f9c4bb60426abaf9#RBmcvFnf5+wFwP54IM8f7pUSvmPn2aOFm1Z6LbIOFK8=

The URL contains two parts:

  1. A half MD5 hash (16 a-f and 0-9 hash)
  2. Followed with one "#" then a base64 encoded string

I'm trying to ask if the URL containts the 16 alphanumeric chars, and if yes, I want to redirect the whole URL (including the #hash followed info) to a new directory.

I'm trying with this Rule:

RewriteRule ^\\?[a-f0-9]{16}$ /newdirectory/$1 [L]

But of course it doesn't work. What is the correct regex for the redirection? Thank you so much!

1
  • @anubhava Something like this: http://example.com/?7027fcbbc2a1ccb9#N61/vMSRNqYQBhb+DcaSfv2YGW1HiBbSpMUoSHrtxok= and i want redirect to: http://example.com/newdir/?7027fcbbc2a1ccb9#N61/vMSRNqYQBhb+DcaSfv2YGW1HiBbSpMUoSHrtxok= Regards! Commented Jul 7, 2017 at 16:02

1 Answer 1

1

What you have in your URL is actually a query string not request URI. You can use this rule in your site root .htaccess:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^[a-f0-9]{16}$ [NC]
RewriteRule ^/?$ /newdir/ [L,R=301,NE]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.