简体   繁体   English

删除子文件夹并使用htaccess在URL中获取pageName

[英]removing subfolder and get pageName in url using htaccess

I want to remove the sub folder from url and get the page name from the url using .htaccess . 我想从url中删除子文件夹,并使用.htaccess从url中获取页面名称。

Suppose my real directory structure is: 假设我的真实目录结构是:

 /public_html/promoted-content/gui/promoted-content.php
 /public_html/promoted-content/pages.php

Pages.php Pages.php

 switch($_GET['pageName']) {

    case 'home': {
        include "gui/promoted-content.php";
        break;
    }

    case 'promoted-content-news': {
        $default_title = "News | ".$default_title;
        include "gui/promoted-content.php";
        break;
    }


    case 'promoted-content-news-details': {
        $default_title = "News | ".$default_title;
        include "gui/promoted_contentdetail.php";
        break;
    }

.htaccess 的.htaccess

  RewriteRule ^([A-Za-z0-9-]+)/?$ promoted-content/index.php?pageName=pages&id=$1    [NC,L]    # Process Pagename requests

So, I want url www.example.com/promoted-content/gui/promoted-content.php?id=1 to be rewrited as: 因此,我希望将网址www.example.com/promoted-content/gui/promoted-content.php?id=1重写为:

 www.example.com/promoted-content-news/pageid/pagetitle

You need to catch 3 parameters in .htaccess , one for your pageName, one for id, and one for title: 您需要在.htaccess中捕获3个参数,一个用于您的pageName,一个用于ID,一个用于标题:

#make sure existing files and directories work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([0-9]+)/(.*)$ promoted-content/index.php?pageName=$1&id=$2&title=$3 [L]

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

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