How does RewriteBase work in .htaccess?

7

I've always used .htaccess to url's amigáveis no php , but recently when I moved to the server of a company X, the .htaccess that always worked did not work on that server ....

After searching, I discovered that just putting RewriteBase / to it works ...

Could anyone clarify how this RewriteBase works and how does it affect mod_rewrite ?

    
asked by anonymous 23.09.2014 / 22:07

1 answer

6

Well, RewriteBase is a directive that specifies the prefix of the URL that will be used to replace a relative path, that is, you can write a base path for your rewrites . It is very useful in situations where your code is not in the root directory of the server.

This is a very simple example, taken from Apache documentation , which represents the operation of RewriteBase .

<Directory /opt/myapp-1.2.3>
    RewriteEngine On
    RewriteBase /myapp/
    RewriteRule ^index\.html$  welcome.html 
</Directory>

In this case the root directory of the application is not in the same directory as the server, so with RewriteBase you will be telling the server that when that route is requested it should run the application located in% / p>

As for /opt/myapp-1.2.3 , it is the module responsible for working with the writing rules of friendly URLs that will be defined in mod_rewrite .

    
24.09.2014 / 02:19