Home > Net >  Add part to a URL via htaccess
Add part to a URL via htaccess

Time:01-13

I have asked another question on here with the premise of limiting download speeds via PHP and I have since come to conclusion that using mod_limitrate was the best solution. so using the following code I have successfully managed to limit the download speed.

<Location "/limit5">
    SetOutputFilter RATE_LIMIT
    SetEnv rate-limit  5120
    SetEnv rate-initial-burst 5120
</Location>

<Location "/unlimited">
    SetOutputFilter RATE_LIMIT
    SetEnv rate-limit  204800
    SetEnv rate-initial-burst 204800
</Location>

However my file structure was not built with this in mind so everything is on the / directory, the following is my file structure

/downloads
-> /downloads/1.zip
-> /downloads/2.zip
...
...

Which makes my download links https://example.com/downloads/1.zip so is it possible to add a part to the URL such as https://example.com/limit5/downloads/1.zip however would still direct to https://example.com/downloads/1.zip ?

I am presuming htaccess is the answer, but I'm not sure how to go about this.

CodePudding user response:

You can try this rule in your Apache VirtualHost config or in site root .htaccess:

RewriteEngine On

RewriteRule ^/?\w (/downloads/. )$ $1 [L,NC]

If you want to allow only 2 parts before downloads/ then use:

RewriteRule ^/?(?:limit5|unnlimited)(/downloads/. )$ $1 [L,NC]
  • Related