htaccess编辑(将链接重写为另一种类型) [英] htaccess editing ( rewrite links to another type )

查看:63
本文介绍了htaccess编辑(将链接重写为另一种类型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件共享脚本,当我上传文件时,文件的下载链接显示如下: http://www.example.net/file?id=fileID

I've a file sharing script, When I upload a file, the download link of the file is showing as this : http://www.example.net/file?id=fileID

请注意,(file?id = fileID)是由函数php文件给定的,而链接的原始形状是:download.php?id = fileID.

Noting that the ( file?id=fileID ) is given by a functions php file .. while the original shape of links : download.php?id=fileID.

现在,当我浏览链接 http://www.example.net/file?id时= fileID ...我没有找到..,而htaccess具有以下内容:

Now when I browse the link http://www.example.net/file?id=fileID ... I get Not found .. and the htaccess has the following :

RewriteRule ^file([0-9]*)?id=$ download.php?id=$1

,仍然找不到. 因此,当我浏览链接时,我想重写原始链接以使其正常工作: http://www.example.net/file?id=fileID

and it still not found.. So I want to Rewrite the original links to work when I browse the link: http://www.example.net/file?id=fileID

推荐答案

这应该有效

RewriteRule ^file/? download.php [QSA]

我使用了QSA标志,因为它保留了查询字符串并将其传递给新的URL.默认情况下,RewriteRule将放弃查询字符串.

I used the QSA flag because it retains the query string and passes it on to the new URL. By default, RewriteRule will discard the query string.

根据您的评论,使用此规则来实现您想要的.

Based on your comment, use this rule to achieve what you want.

RewriteCond %{QUERY_STRING} ^(.*)img(.*)$
RewriteRule ^download.php/? img.php?%1id%2 [QSA]

这篇关于htaccess编辑(将链接重写为另一种类型)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆