doudu3961 2017-01-03 05:52
浏览 105
已采纳

不同类型的URL

I see websites where they have an index page and then their url reads

index.php?page=page

I was wondering how i would do that for my own website using a folder called pages and loading the content of those pages onto my index page while using that url type.

If that makes sense.

  • 写回答

1条回答 默认 最新

  • doushai7225 2017-01-03 05:59
    关注

    Say you have following structure:

    index.php
    pages
        page1.php
        page2.php
        pageN.php
    

    So make use of $_GET to get the page name:

    index.php

    if(isset($_GET['page']) && !empty($_GET['page'])) {
        $pagename = $_GET['page'];
        if(file_exists("pages/$pagename.php")){
            include_once "pages/$pagename.php";
        }
    }
    

    When URL has index.php?page=page1, it checks for page1.php inside pages folder. If file exists, it includes that file inside index.php. Similarly for other pages.


    This is a simple outline idea though. You can develop further, introduce validations. And again, use pretty URLs to make it better for SEO. It can be done by adding few lines to .htaccess file. URL then will be domain.com/page1 or something as you configure.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入