URL friendly redirects to index.php

Asked

Viewed 231 times

0

I’m having trouble directing my friendly url to specific pages. When I click on authorized-resellers for example, it’s taking me to index.php

I have the code vars.php

 <?php
    //var_dump($_SERVER);
function parse_path() {
  $path = array();
  if (isset($_SERVER['REQUEST_URI'])) {
    $request_path = explode('?', $_SERVER['REQUEST_URI']);

    $path['base'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/');
    $path['call_utf8'] = substr(urldecode($request_path[0]), strlen($path['base']) + 1);
    $path['call'] = utf8_decode($path['call_utf8']);
    if ($path['call'] == basename($_SERVER['PHP_SELF'])) {
      $path['call'] = '';
    }
    $path['call_parts'] = explode('/', $path['call']);

    $path['query_utf8'] = urldecode($request_path[1]);
    $path['query'] = utf8_decode(urldecode($request_path[1]));
    $vars = explode('&', $path['query']);
    foreach ($vars as $var) {
      $t = explode('=', $var);
      $path['query_vars'][$t[0]] = $t[1];
    }
  }
return $path;
}



?>

<?php
switch($path_info['call_parts'][0]) {
    case 'aunimed': include 'aunimed.php';
        break;
    case 'revendas-autorizadas': include 'revendas-autorizadas.php';
        break;
}

?>

Not

And I have in my . htaccess

<IfModule mod_rewrite.c>

      RewriteEngine on

      RewriteCond %{REQUEST_FILENAME} !-f

      RewriteCond %{REQUEST_FILENAME} !-d

      RewriteRule ^ index.php [L]

    </IfModule>

Inside every page I’m calling

<?php require('vars.php'); ?>
  • When you say "friendly url" is removing ". php" from url?

  • Exactly @Miguel

1 answer

1


Don’t even need it, just use the .htaccess thus:

<IfModule mod_rewrite.c>
RewriteEngine On
    #URL's Amigáveis - friendly urls
    RewriteRule ^index/?$ index.php [NC,L]
</IfModule>
  • I changed the code, but when I go to the URL it appears: The requested URL /authorized resales was not found on this server.

  • Well, there you have to put the other tbm url (/resellers-authorized).

  • 1

    On the other line below RewriteRule ^index/?$ index.php [NC,L] just put RewriteRule ^revendas-autorizadas/?$ revendas-autorizadas.php [NC,L] For example. And so you what to do on all pages you want url friendly. Another tip is to use [QSA,L] instead of [NC,L], 'cause then you can use the $_GET at will...

  • Understood. Now it works. Thank you very much for your help!

  • You’re walcome!

Browser other questions tagged

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