0

我有 WordPress 网站,其中包含电影和演员自定义帖子类型。我也在与电影和演员建立关系。

我有一个页面列出与演员有关的电影。在此页面上,访问者可以看到演员在哪些电影中扮演角色。

这个页面的 URL 是这样的:

http://www.mywebpage.com/actors-films/?id=123456

id指演员,id我正在做一个查询并将其显示在页面上。此页面也支持分页,此 URL 也可以:

http://www.mywebpage.com/actors-films/page/2/?id=123456

actors-filmpage 是使用自定义模板的页面,此模板确定演员 ID 并显示他的电影。

一切正常,但我想更改 URL 对 SEO 友好一点。

我尝试了许多 URL 格式

  1. http://www.mywebpage.com/actors-films/jim-carrey 我不知道为什么,但是这个 URL 会重定向到演员页面。

    http://www.mywebpage.com/actors/jim-carrey 
    
  2. http://www.mywebpage.com/actors-films/123456-jim-carrey 我试图捕捉这种 URL.htaccess但没有办法捕捉它,它总是显示 404 not found。

所以,我需要用分页支持重写,你能建议我这样做吗?

编辑:这是我的 .htaccess 文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^actors-films/([0-9]*)\-([^/]*)$  ^actors-films/?id=$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]
</IfModule>

编辑:我意识到不是规则对我有用:示例:
http ://www.mywebsite.com/tex 显示了一个带有此规则的 404:RewriteRule ^/tex /index.php [L]

4

1 回答 1

0

这是解决方案,创建一个名为

add_filter('query_vars', 'ap_register_query_vars');

function ap_url_redirect_rules(){
    add_rewrite_rule('actors-films/([^/]*)','index.php?pagename=artist-film-list&actor_slug=$matches[1]','top');
    flush_rewrite_rules();
}

function ap_register_query_vars($query_vars){
    $query_vars[]='actor_slug';
    return $query_vars;
}

现在我们可以调用 url http://mywebsite.com/actors-films/john-doe

于 2013-08-14T15:33:19.130 回答