【问题标题】:removing ?page=add_theme from the url从 url 中删除 ?page=add_theme
【发布时间】:2021-12-19 13:42:18
【问题描述】:

最近我一直在尝试一些东西,并试图添加一个像 wordpress 这样的主题系统(而不是创建一个全新的 wordpress),只是试图实现他们的登录。

我有这个 index.php 文件

<?php
    include('core/core.php');

    echo $_GET['id'];

    $currentTheme = getPageData() -> theme_selected;
    
    include("jtq-theme/" . $currentTheme . "/index.php");

?>

所以这基本上在主页上显示http://xxxxx/jtq-theme/default/index.php。 所以现在当一个人进入关于我们的页面时。

所以 index.php 是显示所有内容的主文件。 并且关于我们的页面正在使用逻辑显示

http://xxxx/index.php?page=about_us

但我希望网址是

http://xxxx/about_us

并且文件应该从 http://xxxx/jtq-theme/default/about_us.php

在这种情况下我应该如何编写 .htaccess?

【问题讨论】:

    标签: php wordpress .htaccess


    【解决方案1】:

    将此重写规则添加到您的 htaccess 文件中:

    RewriteCond %{QUERY_STRING}    "page=" [NC] 
    RewriteRule (.*)  /$1? [R=301,L]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    

    它将您的请求从 xxxx/index.php?page=about_us 更改为 xxxx/about_us

    更新:

    要在about_us 页面中获取数据,您应该在index.php 文件中添加一个条件:

    <?php
        include('core/core.php');
    
        echo $_GET['id'];
    
        $currentTheme = getPageData() -> theme_selected;
    
        $page = $_GET['page'];    
        if ($page == "about_us") {
            include("jtq-theme/" . $currentTheme . "/about_us.php");
        } else {
            include("jtq-theme/" . $currentTheme . "/index.php");
        }
        
    
    ?>
    

    【讨论】:

    • 嘿@pejman 非常感谢您的回复。当我转到 url xxxx/about_us 时,它没有在 jtq-theme/default/about_us.php 中找到 about_us.php 页面
    • 你在浏览器中看到了什么?
    • 未找到 在此服务器上未找到请求的 URL。
    • @AhadAman 检查答案更新
    • 错误仍然存​​在,xxxxxx/?page=about_us xxxxx/about_us
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多