0

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

www.example.com/folder/?id=35467

id并且title来自数据库。我要把 htaccess 文件放到“文件夹”中。

4

2 回答 2

0

如果要添加 htaccess 文件,/folder/那么您需要以下规则:

RewriteEngine On
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.*)\.html ?id=$1 [L]

要使用 id 查询字符串重定向访问,您可以$_SERVER['REQUEST_URI']检查index.php.

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();
}
于 2013-10-17T13:29:19.537 回答
0

.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>

索引.php

list (,,$id,$title) = explode('/', $_SERVER['REQUEST_URI']);
$link = 'www.example.com/folder/?id='. $id;
于 2013-10-17T13:15:19.477 回答