【问题标题】:Wordpress custom listing pageWordpress 自定义列表页面
【发布时间】:2013-08-14 23:33:19
【问题描述】:

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

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

这个页面的网址是这样的:

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

id 指的是演员,这个id 我正在做一个查询并在页面上显示它。 这个页面也支持分页,这个网址也可以:

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

actors-film页面是一个使用自定义模板的页面,这个模板决定了演员的id并展示了他的电影。

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

我尝试过很多网址格式

  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 我尝试用.htaccess 捕捉这种URL,但没有办法捕捉它,它总是显示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]

【问题讨论】:

  • 向我们展示您当前的.htaccess 并更改任何敏感信息(如果有)。
  • 尝试删除规则周围的&lt;IfModule&gt; 标签。如果出现错误,则不会加载重写模块。

标签: .htaccess url-rewriting


【解决方案1】:

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

的页面
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;
}

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

【讨论】:

    猜你喜欢
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    相关资源
    最近更新 更多