简体   繁体   English

如何从 URL 中删除文件夹名称

[英]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.我为我的博客文章创建了一个单独的文件夹,但现在我遇到了这个问题: https : //www.piximum.co/blogposts/blog1/Website-in-the-age-of-social-networks我想删除来自 URL 的文件夹名称 (blogposts/blog1),但我找不到任何可用的 .htaccess 代码来执行此操作。 Can someone provide me some working .htaccess code for solving this problem?有人可以为我提供一些有效的 .htaccess 代码来解决这个问题吗?

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 文件的索引文件,例如:

<?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我在每个 php 文件的开头添加了这个以防止直接访问 php 文件

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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