从DB中的Pages表创建URL路径

时间:2016-09-09 23:01:22

标签: php apache .htaccess mod-rewrite path

我的网站和数据库存在问题。我创建了一个pages表,我想在其中使用page title作为路径。

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

我使用.htaccess文件:

# 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

但是它没有用?我是否需要创建目录文件夹?

1 个答案:

答案 0 :(得分:0)

将所有请求推送到索引页面,然后该页面将仅发送到浏览器。您的服务器$_SERVER['REQUEST_URI']应该更改,但应始终通过index.php页面运行:

<强> /。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);