Split into URL AMIGAVEL without creating folder

Asked

Viewed 331 times

0

Hello, I am running a website and starting to work with friendly Urls, with this structure I can perform the procedure normally and redeem the values.

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

have today it works: site.com/contact and website.com/company

but wanted to create type: site.com/plans/fiber and site.com/client/registration.

The 1° example is working properly but I’m not able to apply divisions without using folders.

my structure is .htaccess

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

mine 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;  
        ?>

1 answer

1


You need to specify rules in your htaccess this way:

Rewriterule contato? index.php? area=contact [L]

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

Explaining the above rule: I am saying that any url within that contact-started domain should redirect to the index.php page by passing the url argument to the GET area variable.

client/registration and /plans/fiber

Other examples:

Rewriterule client/cadaster? index.php? area=cadas_clients [L]

Rewriterule planes/fiber? index.php? area=planes [L]

Inside your php will create a switch with the $_GET['area'] variable and perform the content separation.

  • In the question code, in the case of /cliente/cadastro, the value in url will be cliente/cadastro, that in the index php. is separated into $Url[0] and $Url[1]. Why doesn’t it work?

Browser other questions tagged

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