我想问你们,因为我有一个问题,我的重写规则,我想不出它如何写好的一个。我有这样的规则:
RewriteRule ^wp-content/uploads/(.*[^(.js|.swf)])$ authenticate.php?file=$1
我想要做的是,每次有人试图在authenticate.php
上传时将用户重定向到wp-content
,我想将文件名发送到php。
例如:
http://domain.tld/wp-content/uploads/2015/11/something.pdf
重定向到authenticate.php?file=something.pdf
但不幸的是我的regexp坏了。有人能帮我吗?
真的谢谢你!
发布于 2015-11-09 05:20:46
在你的.htaccess
里试试这个
RewriteCond %{REQUEST_URI} !(?:js|swf)$ [NC]
RewriteRule ^wp-content/uploads/(.+)$ authenticate.php?file=$1 [NC,L]
对于http://domain.tld/wp-content/uploads/2015/11/something.pdf
,结果是:http://domain.tld/authenticate.php?file=2015/11/something.pdf
发布于 2015-11-09 04:36:42
尝试使用这个正则表达式与负的外观:
^.*?wp-content\/uploads\/.*?\.(?!js$|swf$)[^.]+$
以下URL将与regex匹配:
http://cpsma.ie/wp-content/uploads/2015/09/CPSMA-Newsletter-No-35-Sept-2015-2.pdf
但是,以.js
或.swf
结尾的类似URL将不匹配。因此,以下两个URL与regex不匹配:
http://domain.tld/wp-content/uploads/2015/10/javascript.js
http://domain.tld/wp-content/uploads/2015/02/shockwavefile.swf
您可以在这里测试这个正则表达式:
https://stackoverflow.com/questions/33609105
复制