How to modify the view path with htaccess

Asked

Viewed 203 times

1

I’m creating a htaccess to redirect the URL, for example:

I have the following URL:

   www.site.com.br/view/html/cliente.html
   www.site.com.br/view/html/relatorio/demonstrativoDeDebito.html

and I’d like to keep it that way

   www.site.com.br/cliente
   www.site.com.br/relatorio/demonstrativoDeDebito

mine htaccess and this, it just removes the HTML at the end of the files:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

1 answer

2


Use the RewriteBase and set the whole path in Regex and the file . htaccess should be in the root folder.

You should use to point everything to the folder /view/html:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ /view/html/$1.html

You can also check if the path already starts with view/html/ and ignore these:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(?!view/html/.*)(.*)$ view/html/$2.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.