【问题标题】:Redirecting URL in WordPress在 WordPress 中重定向 URL
【发布时间】:2013-08-31 13:35:15
【问题描述】:

我想以以下形式重定向 URL http://a_domain_name.com/2013/08/link_name/feedhttp://a_domain_name.com/link_name/feed。我是 WordPress 初学者,发现很难做到这一点。最好的方法是什么?

我尝试将安全重定向插件与http://domain_name.com/%year%/%monthnum%/%postname%/feed 一起使用到http://domain_name.com/%postname%/feed,但它不起作用

【问题讨论】:

标签: regex wordpress .htaccess


【解决方案1】:

正确的方法

登录 wordpress 管理面板并转到设置>永久链接页面。

从这里,选择倒数第二个选项,即:

http://domain.com/blogname/blog/sample-post/


或者,您可以创建一个重定向文件。这涉及稍微修改 wordpress。如果您对 wordpress 和 php 不满意,我不建议您这样做。为此,首先:

在管理面板中打开设置>永久链接页面:

选择列表中的最后一个选项(自定义)并输入如下内容:

/redirect.php?p=%post_id%&a=%author%&c=%category%

您还需要将以下两个可选表单更改为:

类别库

/redirect.php?c=

标签库

/redirect.php?t=

现在,让我们创建一个重定向 php 文件。把它放在 /yourblogname/blog/

<?php 


$total=0;

$string = 'http://www.yourdomain.com/';
$fetch = '';

if (isset($_GET['p'])&&!is_null($_GET['p']))
{
    $p = $_GET['p'];
    if ($total ==0) {
        $string.='?p='.$p;      
    } else {
        $string.='&p='.$p;
    }
    $total++;
}
if (isset($_GET['t'])&&!is_null($_GET['t']))
{
    $t = str_replace('/','',$_GET['t']);
    if ($total ==0) {
        $string.='?tag='.$t;
    } else {
        $string.='&tag='.$t;
    }
    $total++;
}
if (isset($_GET['a'])&&!is_null($_GET['a']))
{
    $a = $_GET['a'];
    if ($total ==0) {
        $string.='?a='.$a;
    } else {
        $string.='&a='.$a;
    }
    $total++;
}
if (isset($_GET['s'])&&!is_null($_GET['s']))
{
    $s = $_GET['s'];
    if ($total ==0) {
        $string.='?s='.$s;
    } else {
        $string.='&s='.$s;
    }
    $total++;
}
if (isset($_GET['c'])&&!is_null($_GET['c']))
{
    $c = str_replace('/','',$_GET['c']);
    if ($total ==0) {
        $string.='?category_name='.$c;
    } else {    
        $string.='&category_name='.$c;
    }
    $total++;
}



echo '<head><meta http-equiv="Refresh" content="0; URL='.$string.'">';
?>
<style>
html {
    background:black;
    color:white;
}
</style>
</head>
<body>
<div id=cont>
<p align=center><div style='font-size:72px;text-align:center;' ><?php echo "redirecting..."; ?></p></div>
</div>
</body>

我们还没有完成。我们需要调整我们现在重定向到的页面... (index.php)

if (!isset($_GET['p'])) { 
    if (!isset($_GET['category_name']) && !isset($_GET['tag']) && !isset($_GET['s']) && !isset($_GET['search']) ) {
            include('newhome.php'); //frontpage with no special redirect
    } else {
        include('listabbrposts.php');  //a list of abbreviated posts for browsing
    }
} else {
    include('entry.php');  // a page with a single article
}

对于一个工作示例,您可以查看我使用此技术的页面:http://www.artfuladvection.com 从左侧单击主题或标签以查看重定向。

【讨论】:

  • 我只想说使用更长的方法会导致挫败感,并且需要在多个文件中进行编辑。如果您是 wordpress 新手,最好使用预设的永久链接模板之一。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-10
  • 2011-05-30
  • 2017-06-01
  • 2010-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多