2012-02-21 41 views
-1

我有一個數據庫表與一些用戶生成的內容。每個內容元素都可以通過/ my-url/project/the-projects-name獲得。這些項目是沒有WordPress的帖子。我創建了一個索引腳本,在重定向到這樣的URL時被調用。該腳本然後提取項目名稱,將其放入一個變量幷包含一個頁面模板。 我的頁面和項目數據顯示的很好,但wordpress會爲請求的網站引發404狀態,並將標題設置爲「Not Found!」。我怎樣才能僞造wordpress輸出?自己的重寫規則爲WordPress的特殊網址

我的htaccess其重定向到我的指數projects.php腳本:

RewriteCond %{REQUEST_URI} ^/my-url/project/(.*) 
RewriteRule . /index-project.php [L] 

我的指數project.php:

ob_start(); 

define('WP_USE_THEMES', true); 

$path = explode('/', $_SERVER['REQUEST_URI']); 

while(empty($path[0])) 
    array_shift($path); 

while(empty($path[count($path)-1])) 
    array_pop ($path); 

if(count($path) >= 3 && !empty($path[2])) { 

$postFound = false;        // use this param to define if requested post was found in DB 
$post_name = $path[2];       // get the post name from url 

$args = parse_url($post_name); 

$slug = $args['path']; // extract the post slug from post name 

if(!empty($slug)) { 
    $wp_did_header = true; 

    $_GET['page_id'] = SOME_ID_OF_MY_WP_PAGE; 
    $_GET['main_page'] = 'page-project'; 
    require_once(dirname(__FILE__) . '/wp-load.php'); 
    wp(); 

    include('./wp-content/themes/my-theme/page-project.php'); 
    } 
} 

回答

0
RewriteRule ^/my-url/project/(.*) /index-project.php [L] 

RewriteRule ^/index-project.php - [L] 

,並確保你把它有關WP規則在你的htaccess

+0

WordPress的仍然拋出404頁裝入正確,內容是「重定向」我的指數project.php但WP仍然返回404頭到瀏覽器... – Denis 2012-02-22 08:26:15

+0

我想有一些東西必須添加到index-project.php腳本,以告訴WordPress不會搜索url所請求的頁面/帖子 – Denis 2012-02-22 08:29:26

0

Wordpress仍然會拋出一個404頁面正確加載和內容被「重定向到」我的指數project.php但WP仍返回404頭到瀏覽器:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^my-url/project/(.*) /index-project.php [L] 
RewriteRule ^/index-project.php - [L] 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule>