我正在尝试使用apache-rewrite规则来转换以下URL:
@H_301_30@
http://localhost/foo/bar/news.PHP?id=24
进入这种格式:
http://localhost/foo/bar/news/foo-bar
数字24是MySQL表中随机行的id,其中还包含标题和内容字段.
MariaDB [blog]> select * from articles; +----+---------+----------+ | id | title | content | +----+---------+----------+ | 1 | foo-bar | bla bla | +----+---------+----------+ 1 row in set (0.00 sec)
我的.htaccess中有以下规则:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l ^news/([A_Za_z0_9_]+)$DIRECTORY/AID/news.PHP?id=$1 [QSA,L]
$link = "<a href='news.PHP?id={$row['id']}'></a>"; echo $link;
但是,我无法获得重写规则来将路径更改为所需的最终结果.