Apache .htaccess mod_rewrite RewriteCond 问题
我试图让 RewriteCond/RewriteRule 对正常工作,这会导致 404 错误,除非我取消注释 RewriteCond,在这种情况下,所有内容都会被重定向。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /path/
RewriteCond /var/www/site/downloads/$1 -F
RewriteRule ^(.+)$ getdownload.php [L]
</IfModule>
这个想法是,如果文件存在于下载目录中,则将用户发送到 getdownload.php 脚本,该脚本将分发下载(假设他们有权限)。
关于为什么这会失败有什么想法吗?
I'm attempting to get a RewriteCond/RewriteRule pair working, which results in a 404 error unless I uncomment the RewriteCond, in which case everything is redirected.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /path/
RewriteCond /var/www/site/downloads/$1 -F
RewriteRule ^(.+)$ getdownload.php [L]
</IfModule>
The idea is, if the file exists in the downloads directory to send the user to the getdownload.php script, which distributes the download, assuming they have permission.
Any thoughts as to why this would be failing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仍然在 URL 中显示 downloads/index.php,但提供 /downloads/getdownload.php 内容,并确保它是一个文件。 (注意:我的 .htaccess 文件位于我的测试站点的顶层。)
如果您想将其放入 /downloads/ 中,您可以从规则两侧删除“path/downloads/”。
Still shows downloads/index.php in URL, but serves /downloads/getdownload.php content, AND makes sure it's a file. (note: my .htaccess file is in the top level of my test site.)
If you want to put it into /downloads/ you can delete "path/downloads/" from both sides of the rule.