doukucai0099 2016-09-09 23:01
浏览 20

从DB中的Pages表创建URL路径

I'm having issues with my website and database. I created a pages table where I want to use the page title as the path, for instance.

http://website.com/page-title/

I'm using a .htaccess file with:

# BEGIN
<IfModule mod_rewrite.c >
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule >
# END

But it's not working? Do I need to create directory folders?

  • 写回答

1条回答 默认 最新

  • dongya2578 2016-09-11 02:56
    关注

    Push all requests to an index page and then that page will send to the browser only. Your server $_SERVER['REQUEST_URI'] should change but should always run through the index.php page:

    /.htaccess

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !(/$|\.)
    RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?$1 [NC,QSA,L]
    

    /index.php

    <?php
    // You should see the REQUEST_URI change here.
    print_r($_SERVER);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程