How to configure apache to ignore the directory in the url?

0

I have a directory inside my root folder called "mydir" where there are several files, currently I access these files like this:

link

My question is how do I configure .htaccess so I can access (show the user) these files like this:

link

But I do not want to redirect all files, only ".html".

I'm trying on my .htaccess, however I get a 404:

RewriteRule "^/(.+)$" "/mydir/$1"

Where "^ / (. +) $" is the regular expression, which I read in the apache does this mean:

^ = anchor to start the expression.

/ = project root.

(.) = means any character.

+ = repeat the "." one or more times.

/ mydir / = directory which I want to replace.

$ 1 = variable referring to regular expression in parentheses.

$ = anchor to end the expression.

And yet, when I try to access link , I get a page 404 not found error. See that I did not even get the html just yet, but I imagine it would be something like "^ / (.. html) $" where you need to escape. with a backslash.

    
asked by anonymous 25.02.2018 / 21:23

2 answers

0

I think it's something like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(.*)/ 
RewriteCond %{REQUEST_FILENAME} /.+\.html$
RewriteRule (.+) /mydir/$1 [QSA, L]

This condition takes any file .html in the root and rewrites the URL to /mydir/arquivo.html

    
26.02.2018 / 01:19
0

After hours trying I did it. Just do it in your .htaccess, I'll explain:

RewriteEngine On

RewriteCond %{REQUEST_URI} !/mydir/
RewriteRule "^(.+\.html)$" "/mydir/$1"

RewriteEngine On

Enable rewrite mode.

RewriteCond %{REQUEST_URI} !/mydir/ 

To create a condition and deny " /mydir/ " in the loop, otherwise something like: /mydir/mydir/mydir/mydir/mydir/mydir/mydir/mydir/mydir/mydir/

RewriteRule "^(.+\.html)$" "/mydir/$1" 

And finally the rewriting rule, where "^ (. +. html) $" is the regular expression that means it will grab all .html files, notice the need to escape the point, as it is a regular expression character that means "any character," the + is to repeat the point one or more times.

    
26.02.2018 / 06:31