Search code examples
phpapache.htaccesswebserverhttpd.conf

Change links type from .php?id= to html


I have a file hosting and sharing PHP script, which uses the basic type of links, when a file has been uploaded, the basic link of the file will be : http://example.com/do.php?id=1

Noting that the (1) is the file ID.

Now the script has a feature to enable the mod rewrite with HTML links type.. when Activate it .. the link above will be like this: http://example.com/download1.html

Now, the htaccess file need to be edited to change the links to another shape.. So what I want to do is to make the above link looks like: http://example.com/filename_FileID.html or http://example.com/FileID.html or http://example.com/filename_RandomCharectars&numbers.html

and I don't know how to do it .. Please help me editing my htaccess..

Here is the currect htaccess file:

RewriteRule ^download([0-9]*).html$ do.php?id=$1
RewriteRule ^downloadf-(.*)-([a-zA-Z0-9_-]*).html$ do.php?filename=$1&x=$2
RewriteRule ^down-([0-9]*).html$ do.php?down=$1
RewriteRule ^downf-(.*)-([a-zA-Z0-9_-]*).html$ do.php?downf=$1&x=$2
RewriteRule ^downex-([0-9]*).html$ do.php?down=$1
RewriteRule ^downexf-(.*)-([a-zA-Z0-9_-]*).html$ do.php?downexf=$1&x=$2

Solution

  • For http://example.com/FileID.html (I'm assuming "FileID" is going to be a numeric value)

    The rule is

    RewriteRule ^([0-9]*)\.html$ do.php?id=$1
    

    For http://example.com/filename_FileID.html The rule is

    RewriteRule ^filename_([0-9]*)\.html$ do.php?id=$1
    

    For http://example.com/filename_RandomCharectars&numbers.html The rule is

    RewriteRule ^filename_(.*)\.html$ do.php?id=$1