简体   繁体   中英

How to remove folder names from URL

I am making a page for training. This page has a blog with blogposts. I made a separate folder for my blog posts, but now I have a problem with this: https://www.piximum.co/blogposts/blog1/Website-in-the-age-of-social-networks I want to remove folder names (blogposts/blog1) from URL, but I couldn't find any working .htaccess code to do that. Can someone provide me some working .htaccess code for solving this problem?

Here is what I have tried:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase / 
RewriteRule ^blogposts/blog1/(.*)$ /$1 [L,NC,R]

This removes the folder names from link, but link is not going to my post.

I'm using an index file that handles all requests and prevent direct access to php files something like that:

<?php
session_start();
include_once 'includes/autoloader.inc.php';

define('NotDirectAccess',True);
if (isset($_SESSION['mydata'])){
      if(isset($_GET['questions'])) {
        require_once 'View/questions.php';
      }else if(isset($_GET['tests'])) {
        require_once 'View/tests.php';
      }else if(isset($_GET['groups'])) {
        require_once 'View/groups.php';
      }else if(isset($_GET['courses'])) {
        require_once 'View/courses.php';
      }else if(isset($_GET['users'])) {
        require_once 'View/users.php';
      }else if(isset($_GET['results'])) {
        require_once 'View/results.php';
      }else if(isset($_GET['profile'])) {
        require_once 'View/profile.php';
      }else{
        require_once 'View/home.php';
      }
}else{
    if(isset($_GET['register'])) {
        require_once 'View/register.php';
    }else if(isset($_GET['reset'])) {
      require_once 'View/reset.php';
    }else{
        require_once 'View/login.php';
}}

and i added this at the beginning of each php file to prevent direct access to php files

if (!defined('NotDirectAccess')){
    die('Direct Access is not allowed to this page');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM