I can not capture ROTA without using index in URL

1

In short, it only works if I put index.php in the URL. It looks like it's in .htaccess, but I do not know where. I would like to know which setting is incorrect or what I could do to find out my error.

Data: Debian (9) Apache / 2.4.25 (Debian) PHP 7.0.19-1

My .htaccess:

<IfModule mod.rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [NC, L]
</IfModule>

My index.php:

<?php
 $url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
 echo $url;
 //tentativa diferente
 $R = filter_input(INPUT_SERVER, 'REQUEST_URI');
 echo $R

Terminal:

$ systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-10-28 12:30:05 -02; 1h 8min ago
Process: 768 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)

$ a2enmod rewrite
Module rewrite already enabled

    
asked by anonymous 28.10.2017 / 18:17

2 answers

0

Your .htaccess appears to be OK. Perhaps the ErrorDocument and FallbackResource directives help you complete what you plan to do (direct all routes, even nonexistent resources, to index.php).

.htaccess

<IfModule mod_rewrite.c>

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php/$1?%{QUERY_STRING} [L]

  ErrorDocument 404 /index.php
  FallbackResource /index.php

</IfModule>

index.php

<?php

   $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
   $query_string = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);

   echo "<strong>PATH:</strong>" . $path . "<br>";
   echo "<strong>QUERY STRING:</strong>" . $query_string . "<br>";

?>

Result:

    
29.10.2017 / 00:14
0

The problem is in the flags delimiter:

 RewriteRule ^(.*)$ index.php/$1 [NC, L]
 #                                  ^^
 #                     não permite espaços aqui

The space is wrong. Change to:

 RewriteRule (.*) index.php/$1 [NC,L]
  • Although you do not really need to ignore .* .


You can test your htaccess at .htaccess check .

  • With your case, say " Fatal: RewriteRule: bad flag delimiters ".
24.11.2017 / 01:40