Split into AMIGAVEL URL without creating folder

0

Hello, I'm creating a website and starting to work with friendly URls, with this structure I can perform the procedure normally and retrieve the values.

Now I would like to create divisions in the URL, for example:

I have today that works: site.com/contact and site.com/company

but wanted to create type: site.com/planos/fibra and site.com/cliente/cadastro.

The 1st example is working correctly because I am not able to apply partitions without using folders.

My structure is .htaccess

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1

My index.php

 <?php      

 $getUrl = strip_tags(trim(filter_input(INPUT_GET, 'url', FILTER_DEFAULT)));
 $setUrl =(empty($getUrl)) ? 'index' : $getUrl;
 $Url = explode('/', $setUrl);

$Url[0] = (!empty($Url[0]) ? $Url[0] : null);
$Url[1] = (!empty($Url[1]) ? $Url[1] : null);
$Url[2] = (!empty($Url[2]) ? $Url[2] : null);


       if (file_exists(REQUIRE_PATH_INC . $Url[0] . '.php')):
            require REQUIRE_PATH_INC . $Url[0] . '.php';
        elseif (file_exists(REQUIRE_PATH_INC . $Url[0] . '/' . $Url[1] . '.php')):
            require REQUIRE_PATH_INC . $Url[0] . '/' . $Url[1] . '.php';
        else:
            require REQUIRE_PATH_INC . '404.php';
        endif;  
        ?>
    
asked by anonymous 10.07.2017 / 21:49

1 answer

1

You need to specify rules in your htaccess like this:

  

RewriteRule ^ contact $ index.php? area = contact [L]

And in your index file perform a routine to load the data by area.

Explaining the above rule: I'm saying that any url within that domain started with contact should redirect to the index.php page passing as an argument from the url to the variable GET area.

  

customer / registration and / plans / fiber

Other examples:

  

RewriteRule ^ client / register $ index.php? area = customer register [L]

     

RewriteRule ^ planes / fiber $ index.php? area = planes [L]

Within your php is to create a switch with the $ _GET ['area'] variable and perform content separation.

    
10.07.2017 / 22:00