S
S
Spoon in the brain2019-01-23 18:37:59
PHP
Spoon in the brain, 2019-01-23 18:37:59

CNC url like VK?

Good evening!
VKontakte uses, as it seemed to me, quite convenient URLs: vk.com/feed
There is a code (I don’t know how correct it is, because I’m still a beginner):
index.php

if ( $_SERVER['REQUEST_URI'] == '/' )
$page = 'home';
else {
$page = substr($_SERVER['REQUEST_URI'], 1); 
if ( !preg_match('/^[A-z0-9]{3,15}$/', $page) ) echo "404";;
}


if ($page == 'home') echo "home";
if else ($page == 'profile') echo "Страница пользователя";
if else ($page == 'news') echo "Новости";

.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Vooot, I thought for a very long time, searched, wrote and really did not work out to make normal urls, as a result I came to this site and I pray, sir, help!
I will be very grateful!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaksPaverov, 2019-01-23
@vessels

.htaccess:

RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

index.php:
<?php
    $url = explode('/',strtolower(substr($_SERVER['REQUEST_URI'], 1)));

    switch($url[0]) {
        case '': { 
            include 'pages/main.php';
            break;
        }
        case 'how_to_buy':{
            include 'pages/how_to_buy.php';
            break;
        }
        case 'payment_methods':{
            include 'pages/payment_methods.php';
            break;
        }
        case 'guarantees':{
            include 'pages/guarantees.php';
            break;
        }
        case 'payment':{
            include 'pages/payment.php';
            break;
        }
        case 'myorders':{
            include 'pages/myorders.php';
            break;
        }
    }
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question