.htaccess conditional redirect based on a string length before being sent to a 404 page

I am trying to setup a redirect either via .htaccess or via a 404.php script. I would prefer the .htaccess route as it would render faster.

I am trying to accomplish the following

Read More

http://domain/{stringlengthof20}
which would get redirected to
http://domain/report.php?name={stringlengthof20}
(of which a report is generated.. so million of variations)..

As this is a wordpress site, there are pages such as http://domain/about-us etc… those would be ignored unless they were 20 characters long

So the heart of the question is does htaccess have a conditional string referral solution where anything but 20 character is rendered normally.. but 20 characters gets treated different? I have read through dozens of pages that make reference to blanket redirect but havent yet seen a conditional one.

or is the only way to modify the 404.php code to check for those 20 characters and redirect from there? (or otherwise generate the 404 page)

or any other ideas? very much appreciated.. thx.

Related posts

Leave a Reply

1 comment

  1. Try :

    RewriteEngine on
    RewriteRule ^([^.]{20})$ /report.php?name=$1 [NC,L]
    

    This will rewrite a uri (of 20 chars) to /report.php?name=uri