Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wordpress中特殊URL的自己重写规则_Wordpress_.htaccess_Rewrite_Http Status Code 404 - Fatal编程技术网

wordpress中特殊URL的自己重写规则

wordpress中特殊URL的自己重写规则,wordpress,.htaccess,rewrite,http-status-code-404,Wordpress,.htaccess,Rewrite,Http Status Code 404,我有一个数据库表,其中包含一些用户生成的内容。每个内容元素都可以通过/myurl/project/projects名称获得。这些项目没有wordpress帖子。我已经创建了一个索引脚本,当调用这样的URL时,我将重定向到该脚本。然后,脚本提取项目名称,将其放入变量中,并包含一个页面模板。 我的页面和项目数据显示良好,但是wordpress为请求的网站抛出404状态,并将标题设置为“未找到!”。我怎样才能伪造wordpress的输出 My htaccess重定向到我的index-projects.

我有一个数据库表,其中包含一些用户生成的内容。每个内容元素都可以通过/myurl/project/projects名称获得。这些项目没有wordpress帖子。我已经创建了一个索引脚本,当调用这样的URL时,我将重定向到该脚本。然后,脚本提取项目名称,将其放入变量中,并包含一个页面模板。 我的页面和项目数据显示良好,但是wordpress为请求的网站抛出404状态,并将标题设置为“未找到!”。我怎样才能伪造wordpress的输出

My htaccess重定向到我的index-projects.php-script:

RewriteCond %{REQUEST_URI} ^/my-url/project/(.*)
RewriteRule . /index-project.php [L]
my index-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');
  } 
}

并确保您在htaccess中输入了关于WP规则的信息,Wordpress仍然抛出404。页面已正确加载,内容已“重定向”到my index-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>

重新启动发动机
重写基/
重写规则^my url/project/(.*)/index-project.php[L]
重写规则^/index-project.php-[L]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]

Wordpress仍然抛出404。页面已正确加载,内容已“重定向”到我的index-project.php,但WP仍会将404标题返回到浏览器……我想必须在index-project.php脚本中添加一些内容,告诉wordpress不要搜索url请求的页面/帖子
<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>