【发布时间】:2016-01-26 08:38:24
【问题描述】:
我目前正在开发一个 CMS,而我的网址目前看起来像这样 example.com/index.php?p=1 我怎样才能使每个帖子都像 p 有一个页面 url,就像 WordPress 一样,它会是标题。
$ArticleName = "Some Example Post";
输出 URL 应如下所示 example.com/some-example-post.php。
【问题讨论】:
我目前正在开发一个 CMS,而我的网址目前看起来像这样 example.com/index.php?p=1 我怎样才能使每个帖子都像 p 有一个页面 url,就像 WordPress 一样,它会是标题。
$ArticleName = "Some Example Post";
输出 URL 应如下所示 example.com/some-example-post.php。
【问题讨论】:
未测试,但可能是这样的。
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9_-]+)\.php$ /index.php?p=$1 [NC,L]
【讨论】:
p=$1 这涵盖了所有潜在的数字还是只是数字 1?
^ 之后左边的字符是第一个占位符的替代 - 在这种情况下 p ~ $1 - 它实际上并不意味着数字 1
foe 时,我当然是指 for - 太早了,看不到直接和咖啡不够 ;-)