Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP将规则重写为数据库值_Php_Database_.htaccess_Url Rewriting - Fatal编程技术网

PHP将规则重写为数据库值

PHP将规则重写为数据库值,php,database,.htaccess,url-rewriting,Php,Database,.htaccess,Url Rewriting,我需要重写 www.example.com/folder/35467/title.html www.example.com/folder/?id=35467 id和title来自数据库。我要把htaccess文件放到“文件夹”中。.htaccess <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on ##########################################

我需要重写
www.example.com/folder/35467/title.html

www.example.com/folder/?id=35467
id
title
来自数据库。我要把htaccess文件放到“文件夹”中。

.htaccess

<IfModule mod_rewrite.c>

    Options +FollowSymLinks
    RewriteEngine on

############################################
## you can put here your script root folder
## path relative to web root

    RewriteBase /

############################################
## never rewrite for existing files, directories and links

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

############################################
## rewrite everything else to index.php

    RewriteRule .* index.php [L]

</IfModule>

如果htaccess文件将位于
/folder/
中,则需要以下规则:

RewriteEngine On
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.*)\.html ?id=$1 [L]
要使用id查询字符串重定向访问,可以检查
index.php
中的
$\u服务器['REQUEST\u URI']
变量

if ( !strpos($_SERVER['REQUEST_URI'],'.html') ) {
    // The request that was made wasn't with the nicer looking URL
    header("Location: /folder/$id/$title.html");
    exit();
}

那么这里真正的问题是什么?你试过什么吗?谷歌搜索URL重写?我已经准备好使用重写,但不是数据库中的值,但您仍然没有提供实际问题。您想要实现什么?我需要将?id=替换为p或任何内容,并从与标题关联的数据库中添加标题值。链接是链接。。您可以使用htaccess操作它们。。DB与此无关..我会试试看,如果有效的话会做标记。否则,我发现:假设您运行的Apache2 web服务器启用了MOD_REWRITE模块,那么这就可以正常工作了。
if ( !strpos($_SERVER['REQUEST_URI'],'.html') ) {
    // The request that was made wasn't with the nicer looking URL
    header("Location: /folder/$id/$title.html");
    exit();
}