Search code examples
phpapache.htaccesswebserver

htaccess editing ( rewrite links to another type )


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


Solution

  • 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]