Redirect access to the file via htacess

0

Good when the user enters some file with .txt in the url of the site I have to send it to an authentication file called download.php

Example, if user type www.meusite.com.br/documento.txt I have to redirect it to the download.php file.

I'm trying to do this:

RewriteRule ^(.+)\.txt$ Download.php

But rather than redirect it is opening the txt file in the browser normally.

Does anyone know how to do this?

asked by anonymous 18.07.2017 / 02:09

1 answer

0

Brother, you could try this:

RewriteRule ^([a-zA-Z0-9_\-]+)\.txt$ download.php?arquivo=$1

Anything started content the letters from a to z in lowercase and from A to Z in uppercase, underline or dash containing one or more characters preceded by .txt redirect to download.php passing as parameter get the name typed without the. txt.

Or you can also do:

RewriteRule ^(.*)\.txt$ download.php?arquivo=$1

Anything preceded by .txt redirects to download by passing the get parameter to the file name.

Note that if your server has nginx in reverse proxy with apache and the extension (mime-type) .txt has been set to resolve in nginx without redirecting to apache, this rule will not work. You should either perform the rewrite directly on the nginx vhost or remove the .txt extension from the mime-types defined in nginx and resolve the rule on apache

vlw!

    
18.07.2017 / 05:14