htaccess editing ( rewrite links to another type )

我怕爱的太早我们不能终老 提交于 2020-01-16 09:38:20

问题


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

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

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

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


回答1:


This should work

RewriteRule ^file/? download.php [QSA]

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.

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

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


来源:https://stackoverflow.com/questions/49100577/htaccess-editing-rewrite-links-to-another-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!