Regex 在WordPress中重定向URL

Regex 在WordPress中重定向URL,regex,wordpress,.htaccess,Regex,Wordpress,.htaccess,我想重定向一个URL,格式为 http://a_domain_name.com/2013/08/link_name/feed至http://a_domain_name.com/link_name/feed。我是WordPress的初学者,发现很难做到这一点。最好的方法是什么 我尝试将安全重定向插件与to一起使用,但它无法正常工作 登录wordpress管理面板,进入设置>永久链接页面 从这里选择倒数第二个选项,即: http://domain.com/blogname/blog/sample-p

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


我尝试将安全重定向插件与to一起使用,但它无法正常工作

登录wordpress管理面板,进入设置>永久链接页面

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

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


或者,您可以创建重定向文件。这需要对wordpress进行一点修改。如果您对wordpress和php不满意,我不会推荐您使用它。要做到这一点,首先:

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

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

/redirect.php?p=%post\u 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>

例如,您可以查看我使用此技术的页面:单击左侧的主题或标记以查看重定向

这个资源有用吗?我只想说,使用较长的方法将导致挫折感,需要在多个文件中进行编辑。如果您是wordpress新手,最好使用一个预设的永久链接模板。
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
}