Allow special characters in .htaccess

0

I have a problem when showing pdf files, in my htaccess I have this:

RewriteRule ^([a-zA-Z0-9/]+)$ index.php?view=$1

Everything is working well for me, but at the moment of sending a url like this:

href="files/RAD.pdf/"
href="files/archivo.pdf/"

There the problem appears to me and it is that it sends me to page 404, that the route does not exist, I think the problem is that my htaccess does not allow .-_&() or any special character. I've been looking for how to do it but without success.

And my index.php I have it in this way to link the views according to the URL that is happening:

 <?php

require('config/Config.php');

if (isset($_GET['view'])) {
  $views = explode("/",$_GET['view']);
  if ($views[0]=="admin") {
    $ruta = $views[1];
  } else {
    $ruta = $views[0];
  }

  if (is_file('enrutadores/'.$views[0].'/'.$ruta.'Enrutador.php')) {
    require('enrutadores/'.$views[0].'/'.$ruta.'Enrutador.php');
  } else {
    include('vistas/404.php');
  }
} else {
  include('enrutadores/indexEnrutador.php');
}

?>

Thanks for the help!

    
asked by Alejo Mendoza 03.08.2018 в 21:43
source

2 answers

1

Those url's throw error because you're looking for ranges a-zA-A , 0-9 and / , but if you notice, the file extension includes a period ( . ).

Change the pattern by adding that missing point and it should work. Same with the other characters you need to include.

RewriteRule ^([a-zA-Z0-9/.]+)$ index.php?view=$1
                         ^

Note: If you add it at the end it is taken as a literal point. Changing it would be taken as a wild card allowing any character, so you should escape it. Example:

RewriteRule ^([a-zA-Z0-9\./]+)$ index.php?view=$1
                        ^^
    
answered by 04.08.2018 в 09:12
0

I have found a solution to my concern, I was reading the documentation of .htaccess and I found a way to allow points in the htc with url to show the pdf files I needed.

RewriteRule ^([a-zA-Z0-9/]+)/(.*)$ index.php?view=$1&file=$2

I added after the first expression ^([a-zA-Z0-9/]+) the following:

/(.*)$

This way I was allowed to enter the pdf file and also pass a second variable get called &file=$2 with that I was able to show the files.

    
answered by 04.08.2018 в 23:48