Problems with RewriteRule in apache 2.22 (in DigitalOcean.comm)

1

I use a cloud server called Digital Ocean . However I'm having trouble trying to create friendly URLs. I activated the module rewrite through the command:

  

sudo a2enmod rewrite

and changed sudo nano /etc/apache2/sites-available/default thus leaving:

<Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
 </Directory>

If, by chance, there is a file with the same name, it does not pass through my .htacess , regardless of the extension

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ sessao.php [NC,L,QSA]

Here too my sessoes.php :

$gets = explode("/",str_replace(strrchr($_SERVER["REQUEST_URI"], "?"), "", $_SERVER["REQUEST_URI"]));

for($i=1; $i<=count($gets); $i++) {
    $var = "p$i";
    $$var = addslashes($gets[$i]);
}
if (file_exists($p1.".php")) {
    include("teste.$p1".".php");
} else {
    header("Location: /");
    exit();
}

Practical example of the situation: If I call http://107.170.237.146/base it loads http://107.170.237.146/base.html if it finds the same, if it does not find it search http://107.170.237.146/base.php , if it does not find it it loads sessoes.php .

But I can check that it always passes first through sessoes.php and then fall into .html or .php.

How can I make it first obey .htaccess ?

    
asked by anonymous 03.03.2014 / 08:12

1 answer

1

I do not know if I understood the use of sessoes.php that you are presenting very well.

From what I've seen, she's rightly discussing how the request was made and then include the respective file.

To this end I would directly use .htaccess by making it the targeting rule for the correct file.

Ex:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /sessao.php?file=$1 [NC,L,QSA]

In this way when calling http://107.170.237.146/base.html who will actually open it is the session.php getting via $ _GET the parameter "file" with the value "base"

And this rule will only work if there is no file named base.html in the root of your webserver, because of the condition:

RewriteCond %{REQUEST_FILENAME} !-f

That translating says that the request can not be a file.

If it does not let me know, I have already implemented several situations with htaccess, and I may be able to help you with your problem.

    
13.03.2014 / 01:33