编辑永久链接(函数和.htaccess)

时间:2014-08-26 21:58:34

标签: php html apache .htaccess mod-rewrite

你好,我想对我的主题有点帮助,我想更改永久链接,所以代码就像这样(下码)并希望像这样

domain.com/slug-from-video?id:$uniq_id/ 和文章: domain.com/article/slug-from-article /

`function makevideolink($uniq_id, $video_title = '', $video_slug = '')
{
    $r = array();
    $url_part = '';

    if (_SEOMOD == 1) 
    {
        if ('' != $video_slug)
        {
            $url_part = $video_slug;
        }
        else if ('' != $video_title)
        {
            $url_part = $video_title .'-video'; // pre-v2.1
        }
        else
        {
            $query  = @mysql_query("SELECT video_title, video_slug FROM pm_videos WHERE uniq_id = '".$uniq_id."'");
            $r      = mysql_fetch_array($query);
            mysql_free_result($query);

            if ($r['video_slug'] != '')
            {
                $url_part = $r['video_slug'];
            }
            else
            {
                $url_part = $r['video_title'] .'-video'; // pre-v2.1
            }
        }
        $video_title_clean = sanitize_title($url_part);

        $return = _URL .'/'. $video_title_clean .'_'. $uniq_id .'.html';
    } 
    else 
    {
        $return = _URL .'/watch.php?vid='.$uniq_id;
    }

    return $return;
}`


    function art_make_link($type = 'article', $args = array())
{
    $url = '';

    $url = _URL .'/';
    switch ($type)
    {
        case 'article':

            if (_SEOMOD)
            {
                $url_part = '';

                if ($args['article_slug'] != '')
                {
                    $url_part = $args['article_slug'];
                }
                else
                {
                    $url_part = sanitize_title($args['title']);
                    if (strlen($url_part) == 0)
                    {
                        $url_part = 'read';
                    }
                    $url_part = 'read-'. $url_part;
                    $url_part = preg_replace('/-video$/', '_video', $url_part); // pre-v2.1
                }
                $url .= 'articles/'. $url_part .'_'. $args['id'] .'.'. _FEXT;
            }
            else
            {
                $url .= 'article_read.php?a='. $args['id'];
            }
        break;

.htaccess代码:

RewriteEngine On
    RewriteRule ^index.html$ index.php
    RewriteRule ^browse-(.*)-videos.html$ category.php?cat=$1
    RewriteRule ^browse-(.*)-videos-([0-9]+)-(.*).html$ category.php?cat=$1&page=$2&sortby=$3
    RewriteRule ^videos.flv(.*)$ videos.php$1
    RewriteRule ^register.html$ register.php
    RewriteRule ^contact_us.html$ contact_us.php
    RewriteRule ^edit_profile.html$ edit_profile.php
    RewriteRule ^suggest.html$ suggest.php
    RewriteRule ^upload.html$ upload.php
    RewriteRule ^upload_avatar.html$ upload_avatar.php
    RewriteRule ^suggest.html$ suggest.php
    RewriteRule ^favorites.html(.*)$ favorites.php$1
    RewriteRule ^login.html(.*)$ login.php$1
    RewriteRule ^newvideos.html(.*)$ newvideos.php$1
    RewriteRule ^topvideos.html(.*)$ topvideos.php$1
    RewriteRule ^profile.html(.*)$ profile.php$1
    RewriteRule ^favorites.html(.*)$ favorites.php$1
    RewriteRule ^memberlist.html(.*)$ memberlist.php$1
    RewriteRule ^playlists.html(.*)$ playlists.php$1
    RewriteRule ^articles/index-([0-9]+).html$ article.php?page=$1
    RewriteRule ^articles/browse-(.*)-([0-9]+).html$ article.php?c=$1&page=$2
    RewriteRule ^articles/tag/([^/]+)/page-([0-9]+)(/)?$ article.php?tag=$1&page=$2
    RewriteRule ^articles/tag/([^/]+)(/)?$ article.php?tag=$1&page=1
    RewriteRule ^articles/popular-([0-9]+).html$ article.php?show=popular&page=$1
    RewriteRule ^articles/(.*)_([0-9]+).html$ article_read.php?a=$2
    RewriteRule ^articles(\/|.html)?$ article.php
    RewriteRule ^article(\/|.html)?$ article.php
    RewriteRule ^pages/(.*)\.html$ page.php?name=$1
    RewriteRule ^playlist/(.*)/([^/]+)(/)?$ watch.php?playlist=$1&vid=$2
    RewriteRule ^playlist/(.*)$ playlists.php?playlist=$1
    RewriteRule ^tags/([^/]+)/$ tag.php?t=$1&page=1
    RewriteRule ^tags/([^/]+)/page-([0-9]+)(/)?$ tag.php?t=$1&page=$2
    RewriteRule ^embed/([^/]+)$ embed.php?vid=$1
    RewriteRule ^([^/]*)_([a-zA-Z0-9]{9}).html$ watch.php?vid=$2
    RewriteRule ^fpembed-(.*).swf$ fpembed.php?vid=$1
    RewriteRule ^rss.xml$ rss.php [L]

0 个答案:

没有答案