I would like to ask you guys because I have a problem with one my rewrite rules and I can’t figure it out how to write the good one.
I have this rule:
RewriteRule ^wp-content/uploads/(.*[^(.js|.swf)])$ authenticate.php?file=$1
What I would like to do is redirect the user to the authenticate.php
every time when someone tries to open something in the wp-content
uploads dir and I would like to send the filename to the php
For example:
http://domain.tld/wp-content/uploads/2015/11/something.pdf
redirect to authenticate.php?file=something.pdf
But unfortunately my regexp is broken. Could someone help me?
Really thanks for it!
Try with that in your
.htaccess
:For
http://domain.tld/wp-content/uploads/2015/11/something.pdf
the result:http://domain.tld/authenticate.php?file=2015/11/something.pdf
Try using this regex with negative lookaheads:
The following URL will match the regex:
However, a similar URL which ends in
.js
or.swf
will not match. Hence, the following two URLs do not match the regex:You can test this regex out here:
Regex101