我试图保护使用mod_rewrite我的MP3在我的htaccess文件。
我读这螺纹:
how to write a .htaccess redirect like stackoverflow does for its questions
htaccess rewrite dynamic mp3 to dynamic php?
How to hide filename from url by using .htaccess
这个网站:
https://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
而这个视频:
https://www.youtube.com/watch?v=uPlZekNEU60
我能够改写文件名与此规则filename.pdf:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.pdf -f
RewriteRule ^([^\.]+)$ $1.pdf [NC,L]
现在,为了保护我的MP3我要重写我的网址
FILENAME.MP3 /?UUID =东西https://cdn.com/123456/t/filename.mp3
我想这条规则:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.mp3 -f
RewriteRule ^([a-zA-Z0-9]{30})$ https://cdn.com/123456/t/$1.mp3 [NC,L]
但它不工作
我想这一个:
RewriteRule ^(\w*.mp3)+)$ https://cdn.com/123456/t/$1 [NC,L]
但是却让网站下载下来:(
任何提示?
你最后RewriteRule
有一个右括号末太多,会重复1次或多次匹配MP3。
如果删除括号离开^(\w*.mp3)+
它仍然会重复一组结构,将匹配该模式\w*.mp3
一次或多次。这将匹配0+次单词字符后跟任意字符由于点和mp3
。
这可能例如匹配zmp3
。如果你想匹配一个点你要逃避它。
我想,你的意思是:
RewriteRule ^(\w+\.mp3/)$ https://cdn.com/123456/t/$1 [NC,L]
你可能会检查查询字符串由一个键/值对:
RewriteCond %{QUERY_STRING} ^uuid=\w+$ [NC]