“wordpress” 标签页面:

  • Blogger转移到Wordpress的rewrite跳转规则

    Blogger转移到Wordpress的.htaccess的rewrite跳转规则。

    这是很久之前写的,一直没有整理出来。刚好今天博客搬家,整理一下发上来。

    这份代码可以吧blogger的相同月份的文章转移到wordpress对应的月份归档里,当然,无论如何是不能从blogger的具体文章跳转到wordpress的对应文章的,这是是最精确、最有利于SEO的做法。

    以下是.htaccess的rewrite代码:

    #BEGIN old blog
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      #post
      RewriteRule ^([0-9]{4})/([0-9]{2})/[A-Za-z0-9_-]+\.html$ /date/$1/$2 [R=301,L]
      #archive
      RewriteRule ^([0-9]{4})_([0-9]{2})_01_archive\.html$ /date/$1/$2 [R=301,L]
    </IfModule>
    #END old blog

    2010.12.12 / 2 条评论 / 分类: 所谓技术

  • Convert Wordpress (P2) Microblog Database to StatusNet

    A few days ago , I tried to convert our Wordpress blog , which was used to be our microblog with P2 theme , to StatusNet . StatusNet is a good microblog system , though it needs more developing .

    I wrote a PHP script to convert the Wordpress database to StatusNet . There’re posts and comments in WP that needs to be converted . Firstly , I said that I had no idea how to convert the replies . And I got a pretty answer "There is alway blood in every revolution" . But finally , I found a  way to convert .

    I had ONLY 2 users in WP , so it got a little simplier to do the converting job . If you have many users , you have to make a right users map about WP and SN , both in user IDs and reply "@"s .

    The "wp_posts" tables in WP needs to be converted , and the usernames in it is easy to convert . However , we need to convert "wp_comments" tables as replies into StatusNet , and the names has no relationship with WP users . So I wrote a function called "getID" to map the commenters in WP to user IDs in SN . And the "getID" function has another funtion , which is to map the WP user IDs to SN user IDs .

    I also import both WP db and SN db into one database to simplify the script .

    Here are the codes :

    <?php
    /*
    By Creke
    http://blog.creke.net
    */
    
    header('Content-Type: text/plain'); 
    
    function getID($i)
    {
    	if($i == 2 || strtolower($i) == 'user1')
    	{
    		return 4;
    	}
    	else if($i == 3 || strtolower($i) == 'user2')
    	{
    		return 3;
    	}
    	else
    	{
    		return 1;
    	}
    }
    
    	$mysql_a='dbhost';
    	$mysql_u='dbuser';
    	$mysql_p='dbpassword';
    	$mysql_n='dbname';
    
    	set_time_limit(10); 
    
    		if($dblink = mysql_connect($mysql_a,$mysql_u,$mysql_p))
    		{
    			if(mysql_select_db($mysql_n))
    			{
    
    mysql_query("SET NAMES 'utf8'");
    mysql_query('TRUNCATE notice ;');
    mysql_query('TRUNCATE conversation ;');
    mysql_query('TRUNCATE reply ;');
    
    $oldID = 0;
    $newID = 1;
    $newConID = 1;
    
    //$SQL = "";
    //$result = "";
    //$myres = 
    
    for($i=0;$i<=505;$i++)
    	{
    		//post
    
    		$oldID = $i;
    		$SQL = 'SELECT * FROM wp_posts WHERE post_type = \'post\' AND ID = '.$oldID;
    		if (!$result = mysql_query($SQL)){
    						echo "Execution ERROR :".mysql_error()." ";
    						echo "SQL is :".$SQL." ";
    		}
    		$myres = mysql_fetch_array($result);
    		if($myres['post_content']==NULL){
    		continue;
    		}
    
    		$mynewproid = getID($myres['post_author']);
    		$myres['post_content'] = str_replace('\'','\\\'',$myres['post_content']);
    
    		$SQL = 'INSERT INTO notice (id,profile_id,uri,content,rendered,created,modified,is_local,source,conversation) VALUES';
    		$SQL .= '('.$newID.','.$mynewproid.',\''.'http://blog.recgo.com/notice/'.$newID.'\',\''.$myres['post_content'].'\',\''.$myres['post_content'].'\',\''.$myres['post_modified_gmt'].'\',\''.$myres['post_modified'].'\','.'1'.',\''.'RecgoWPmblog'.'\','.$newConID.')';
    
    		if (!mysql_query($SQL)){
    						echo "Execution ERROR :".mysql_error()." ";
    						echo "SQL is :".$SQL." ";
    		}
    
    		$SQL = 'INSERT INTO conversation (id,uri,created,modified) VALUES';
    		$SQL .= '('.$newConID.',\''.'http://blog.recgo.com/conversation/'.$newConID.'\',\''.$myres['post_modified_gmt'].'\',\''.$myres['post_modified'].'\')';
    
    		//echo $SQL;
    		if (!mysql_query($SQL)){
    						echo "Execution ERROR :".mysql_error()." ";
    						echo "SQL is :".$SQL." ";
    		}
    
    		$newID2=$newID;
    		$newID++;
    
    		//reply
    		$SQL = 'SELECT * FROM wp_comments WHERE comment_approved = 1 AND comment_post_ID = '.$oldID.' ORDER BY comment_ID';
    		if (!$result = mysql_query($SQL)){
    						echo "Execution ERROR :".mysql_error()." ";
    						echo "SQL is :".$SQL." ";
    		}
    
    		while($myres = mysql_fetch_array($result))
    		{
    			if($myres['comment_content']==NULL){
    			continue;
    			}
    
    			$mynewproid = getID($myres['comment_author']);
    			$commentID2newreplyto[$myres['comment_ID']]=$newID;
    			if($myres['comment_parent']!=0)
    			{
    				$newreplyto=$commentID2newreplyto[$myres['comment_parent']];
    			}
    			else
    			{
    				$newreplyto=$newID2;
    			}
    
    			if($mynewproid == 3)
    			{
    				$myres['comment_content'] = '@user1 '.$myres['comment_content'];
    				$myreplyproid = 4;
    			}
    			else if($mynewproid == 4)
    			{
    				$myres['comment_content'] = '@user2 '.$myres['comment_content'];
    				$myreplyproid = 3;
    			}
    			$myres['comment_content'] = str_replace('\'','\\\'',$myres['comment_content']);
    			$myres['comment_content'] = str_replace('\"','\\\"',$myres['comment_content']);
    
    			$SQL = 'INSERT INTO notice (id,profile_id,uri,content,rendered,created,modified,is_local,source,conversation,reply_to) VALUES';
    			$SQL .= '('.$newID.','.$mynewproid.',\''.'http://blog.recgo.com/notice/'.$newID.'\',\''.$myres['comment_content'].'\',\''.$myres['comment_content'].'\',\''.$myres['comment_date_gmt'].'\',\''.$myres['comment_date'].'\','.'1'.',\''.'RecgoWPmblog'.'\','.$newConID.','.$newreplyto.')';
    
    			//echo $myres['comment_content'].'\n';
    			if (!mysql_query($SQL)){
    							echo "Execution ERROR :".mysql_error()." ";
    							echo "SQL is :".$SQL." ";
    			}
    
    			$SQL = 'INSERT INTO reply (notice_id,profile_id,modified) VALUES';
    			$SQL .= '('.$newID.','.$myreplyproid.',\''.$myres['comment_date'].'\')';
    
    			if (!mysql_query($SQL)){
    							echo "Execution ERROR :".mysql_error()." ";
    							echo "SQL is :".$SQL." ";
    			}
    
    			$newID++;
    		}
    		$newConID++;
    	}
    
    			}
    			else
    			{
    				$self_des = "";
    				echo '<br>Linked to MySQL , Can\'t open database ';
    			}
    		}
    		else
    		{
    			$self_des = "";
    			echo '<br>Unable to link to Database ';
    		}
    		mysql_close($dblink);
    
    exit();
    ?>

    Good Luck ^_^

    2010.05.22 / 暂无评论 / 分类: 所谓技术

  • IIS7下Wordpress中文Tag和目录无法访问完美解决方法(不修改程序)

    方法很简单。新建一个“_chineseuri.php”文件,内容如下:

    <?php
    
    // IIS Mod-Rewrite
    if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
    }
    // IIS Isapi_Rewrite
    else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    }
    else
    {
    // Use ORIG_PATH_INFO if there is no PATH_INFO
    if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) )
    $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
    
    // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
    if ( isset($_SERVER['PATH_INFO']) ) {
    if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
    $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
    else
    $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
    }
    
    // Append the query string if it exists and isn't null
    if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
    $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
    }
    }
    
    require("index.php");
    
    ?> 

    然后建立“web.config”文件,如果已经有同名文件就把原来的删掉,其内容如下:

    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
          	<rule name="Chinese Tag and Category for Wordpress" stopProcessing="true">
              <match url="^(tag|category)/(.*)$" />
              <action type="Rewrite" url="_chineseuri.php"/>
            </rule>
            <rule name="wordpress" patternSyntax="Wildcard">
              <match url="*" />
                <conditions>
                  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
              <action type="Rewrite" url="index.php" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>

    如果你的Wordpress不是装在根目录,则需要更改“<match url="^(tag|category)/(.*)$" /> ”为“<match url="^你的目录/(tag|category)/(.*)$" /> ”。如果你把默认的标签和目录的地址改了,则更改这句话里面的对应内容即可。

    把上面两个文件上传至Wordpress所在的根目录(即web.config所在的目录)覆盖原来的文件即可。

    参考更改Wordpress源文件解决这个问题的文章,我们可以知道,是$_SERVER['REQUEST_URI']和$_SERVER['PATH_INFO']的问题。原因太多了,就不罗嗦了,想要明白解决问题的原理是什么,自己查看上面两份代码吧,呵呵。

    2010.05.13 / 1 条评论 / 分类: 所谓技术

  • Wordpress用.htpasswd保护wp-admin文件夹后访问提示404解决办法

    前情提要:
    当然,推荐的选项是设置密码保护,这意味着你仍然可以在任何地方连接到 wp-admin 目录,
    但我们增加了一道防线,以防越权操作。

    .htaccess 文件
    WP � ADMIN 中的 .HTACCESS 文件如下:
    #this file should be outside your webroot.
    AuthUserFile /srv/www/user1/.htpasswd
    AuthType Basic
    AuthName “Blog”
    require user youruser #making this username difficult to guess can help mitigate password
    brute force attacks.

    .htpasswd 文件
    正如已经说明的,该文件 可以放到网站目录之外的地方,上层目录是个很好的选择。
    $ htpasswd �cm .htpasswd blog
    New password:
    Re�type new password:
    Adding password for user blog
    .htpasswd 文件已经在当前目录中创建了,请确保本文件的地址符合 wp�admin/.htaccess 中
    AuthUserFile 所设置的地址。

    当你试图登录博客时会要求你输入用户名和密码以获得连
    接权限。如果没有出现的话,查看一下加密密码文件,然后查看所提供的地址是否正确。

    出现问题:
    用.htpasswd保护wp-admin文件夹后访问提示404
    我在wp-admin文件夹下写了.htpasswd和.htaccess,.htaccess文件内容如下:

    AuthUserFile /home/public_html/wp-admin/.htpasswd
    AuthName "Please enter your ID and password"
    AuthType Basic
    require valid-user

    然后我再次访问wp-admin时,发现需要验证用户名和密码。
    但当我打开rewrite后,发现访问wp-admin时,跳转到的是wp的404提示页面。

     
    问题分析:
    主机商把错误文档重新定义了,然后访问这个时,发了个401要授权的http头,但由于错误文档重定义,而这时Apache又找不到重新定义的文档,所以就抛出了个404的http头,所以被识别成了404错误。
     
    解决办法:
    在wp-admin文件夹的.htaccess顶部加上
    (使用默认的错误页面)
    ErrorDocument 401 default
    (错误档案使用自己指定字符串)
    ErrorDocument 401 "Unauthorized access"
    (使用自己指定的错误页面)
    ErrorDocument 401 /401.html
    以上方法三选一,其实就是一种方法——重新定义一个存在的401提示页面。
     

    2009.08.11 / 暂无评论 / 分类: 随心随感

  • Wordpress与Discuz的Rewrite共存(方法二)

    WP装在/blog文件夹,DZ装在/bbs文件夹。重写成功。
    这是规则,放在站点根目录下.htaccess即可。
    #这是正确的 wordpress+discuz 共生.htaccess
    <IfModule mod_rewrite.c>
    RewriteEngine On
    #即使DZ装在/bbs目录,还是这么写RewriteBase:
    RewriteBase /
    RewriteRule ^bbs/archiver/((fid|tid)-[\w\-]+\.html)$ bbs/archiver/index.php?$1
    RewriteRule ^bbs/forum-([0-9]+)-([0-9]+)\.html$ bbs/forumdisplay.php?fid=$1&page=$2
    RewriteRule ^bbs/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ bbs/viewthread.php?tid=$1&extra=page\%3D$3&page=$2
    RewriteRule ^bbs/space-(username|uid)-(.+)\.html$ bbs/space.php?$1=$2
    RewriteRule ^bbs/tag-(.+)\.html$ bbs/tag.php?name=$1
    </IfModule>
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #下面如果是WP装在根目录就是RewriteRule . /index.php [L]
    RewriteRule . /blog/index.php [L]
    </IfModule>
    # END WordPress
    这个方法可行,但还是推荐这种方法:http://blog.creke.net/2009/08/wordpressdiscuzrewrite.html。因为它更便于管理

    2009.08.08 / 6 条评论 / 分类: 所谓技术

  • wordpress与discuz的Rewrite共存

    自从使用了CPH的LAMP服务器之后,我就开始在上面试验一些php+mysql应用,其中首先弄的就是discuz了。

    安装了discuz6.0.0之后,基本上运行正常,但是一个最重要的功能urlrewrite一直搞不定,直到今天在本地弄xampp才无意之中发现了问题所在。

    和wordpress不一样,当你在discuz后台选择使用url静态化之后,并不会自动生成相应的.htaccess文件,而是指导你”相应规则请参考《用户使用说明书》的高级使用部分”。
    google一下知道这个Discuz! 用户使用说明书,然后找到高级应用里面的url静态化:http://www.discuz.net/usersguide/advanced_urlrewrite.htm

    按照discuz所说的,对于Apache Web Server(虚拟主机用户),应该进行如下操作:

    检查论坛所在目录中是否存在 .htaccess 文件,如果不存在,请手工建立此文件。Win32 系统下,无法直接建立 .htaccess 文件,您可以从其他系统中拷贝一份,或者在 Discuz.net 技术支持栏目中下载此文件。编辑并修改 .htaccess 文件,添加以下内容

    # 将 RewriteEngine 模式打开
    RewriteEngine On
    # 修改以下语句中的 /discuz 为你的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
    RewriteBase /discuz
    # Rewrite 系统规则请勿修改
    RewriteRule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1
    RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
    RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
    RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
    RewriteRule ^tag-(.+).html$ tag.php?name=$1

    添加内容时,请遵照上面的提示,修改论坛所在的路径,然后保存。将 .htaccess 文件上传到论坛所在的目录中。然后进入论坛系统设置的搜索引擎优化,根据需要开启 URL 静态化功能。

    我这样做了之后不但没有效果,而且连论坛都访问不了,提示HTTP500错误。

    今天在本地安装了xampp之后,装了discuz,重新按照上面的方法测试,还是不行,然后又安装了wordpress并成功使用了urlrewrite。
    打开wordpress自动生成的.htaccess文件和discuz的来比较,终于看出来问题:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    </IfModule>
    # END WordPress

    很明显,discuz官方的资料少了两行:
    <IfModule mod_rewrite.c>
    </IfModule>

    按照wordpress的加上去,在本地和CPH服务器上都成功了。
    我对.htaccess文件不是很懂,完全是自己尝试出来的,补充几点:
    首先是<IfModule mod_rewrite.c></IfModule>不能少,这大概是判断mod_rewrite是否存在的。
    其次是RewriteEngine On这个应该是Rewrite引擎打开,也不能少。
    然后是RewriteBase /这个很重要,如果安装在根目录就保持这样,如果不是,就要把/替换成所在的目录,相对于web根目录。
    例如你把discuz安装在http://127.0.0.1/bbs,那么就要写成RewriteBase /bbs/才可以,这样也方便了多个rewrite共存。
    最后是.htaccess文件的位置,如果你的根目录下有bbs和wordpress两个目录对应http://127.0.0.1/bbshttp://127.0.0.1/wordpress,那么可以分别创建两个.htaccess文件放在这两个目录里。
    例如我是这样的:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    </IfModule>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /bbs/
    RewriteRule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1
    RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
    RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
    RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
    RewriteRule ^tag-(.+).html$ tag.php?name=$1
    </IfModule>

    注意加粗部分哦。

    2009.08.08 / 暂无评论 / 分类: 所谓技术

  • 这不是升级,这是寂寞――Creke ACG升级至wordpress 2.8.3

    这不是升级,这是寂寞——Creke ACG升级至wordpress 2.8.3
     
    这次升级的形象代言人是——绿坝娘同学!

    升级维护页面截图:

    wp_updated_page.jpg

    这不是升级,这是寂寞 | Creke ACG

    如果你以为本站“被维护”,那么很可惜,本站只是升级系统。目前已经升级完毕并恢复正常运作。以下是wordpress成功升级到2.8.3的截图,留念一下:

    wp_updated_suc.jpg

    wordpress成功升级到2.8.3

    话说今天出了wp2.8.3,马上看到有人��地在说:“我刚升级到2.8.2没几天,今天又出新版……”幸亏昨天Creke ACG的在线升级因不明原因没有成功,结果今天一大早就看到wordpress出了2.8.3的新闻,下午就相应看到中文版也出了的新闻。然后今天慢慢覆盖升级,终于也OK了。

    简要概况升级几个步骤:

    1. 升级各种主题、插件等到最新版
    2. 停用各种插件
    3. 将主题换回默认主题
    4. 删除相应缓存
    5. 将最新wordpress系统覆盖网站原系统;或删除相应文件夹后上传新版wordpress,注意不要把插件和主题也删了,否则就再传一遍吧!
    6. 按照提示访问“/wp-admin/upgrade.php”升级数据库,也可能不需要,反正需要就会自动提示的。
    7. 登入后台,启用主题和各个插件,建议启用并配置好其它插件后,最后再启用缓存插件
    8. 升级完了,截个图写个心得充下版面

    新版的Creke ACG的特点:

    1. 更快,更稳定,更安全!
    2. 更X,更H,更��(这是因为管理员的原因)
    3. 特色内容更多更丰富(不然怎么叫特“色”)
    4. 小唧更聪明(向来就不笨,只是天然呆……�……话说有谁给小唧做过人设没?小唧的人工智能库都是根据什么性格开发的呀???�!)
    5. 网站提示更有爱(这个慢慢体会吧)

    以上。

    2009.08.04 / 暂无评论 / 分类: 所谓技术