How does Rewritebase work on . htaccess?

Asked

Viewed 10,339 times

8

I’ve always used the .htaccess for url's amigáveis no php, but recently when passing to a company X server, the . htaccess that always worked didn’t work on that server....

After researching I found that it was only put the RewriteBase / for it to work...

Could someone enlighten me like this RewriteBaseworks and how it affects the mod_rewrite?

1 answer

8


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

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 directory root application is not in the same server directory, so with the RewriteBase you will be telling the server that when that route is requested it should run the application located in the /opt/myapp-1.2.3.

As to the mod_rewrite, is the module responsible for working with the writing rules of the friendly Urls that will be defined in .htaccess.

  • 3

    Note: this example has as assumptions DocumentRoot /var/www/example.com and Alias /myapp /opt/myapp-1.2.3.

Browser other questions tagged

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