【发布时间】:2016-09-13 07:18:51
【问题描述】:
我目前正在创建一个使用自定义 PHP 代码的新网站,但我也在从远程 wordpress 检索 Wordpress 帖子。
在我的根文件夹中(就像 wordpress 一样),我有默认的 wordpress .htaccess 文件:
# BEGIN WordPress
<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 WordPress
我还有一个 index.php 文件,它给了我来自 WP 的帖子:
<?php
// Include the wp-load'er
include('wp/wp-load.php');
// Get the last 10 posts
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 10,
'post_status' => 'publish'
));
...
?>
在我的项目中,我还有其他 custom php 文件,例如 search.php、detail.php 等。
所有 Wordpress 帖子链接都使用如下格式的 slug 进行格式化:www.mywebsite.com/my-post/
问题是,当 URL 不是 .php 文件时,如何更改 .htaccess 文件以便向 index.php 传递 slug 参数? (如 index.php?slug=my-post)
谢谢。
【问题讨论】: