分类目录归档:建站笔记

WordPress: modify the upload list of allowed file types

When you attempt to upload a file in WordPress that is not in the default list of acceptable file types, you will receive the following error: File type does not meet security guidelines. Try another. While there’s no admin-based tool for editing list of allowed file types, it’s not at all difficult to add your own or remove any existing.
Upload filetypes are checked by the function wp_check_filetype in wp-includes/functions.php. But we will add new file types to the file functions.php in our template due to upgrade WordPress.
Open your theme’s functions.php file and add this line somewhere between the <?php and ?>:
 

add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes=array() ) {
// add your extension to the array
$existing_mimes['deb'] = 'application/x-deb';
// add as many as you like
// removing existing file types
unset( $existing_mimes['exe'] );
// add as many as you like
// and return the new full result
return $existing_mimes;
}

In this case I allowed upload .deb files and banned upload .exe files. List of MIME Types can be found here, or use google, if your file type is not in the list (e.g. deb or rpm file type).

IIS7 WordPress 中文 URL 解决方案

1、
使用插件 IIS Chinese Tag Permalink
2、
用 WordPress 写中文博客时 URL 中经常会包含中文字符,一般出现在 Tag 和分类的 URL 中。而 IIS7 对包含中文的 URL 支持有问题。这样的情况下访问如「http://sheng00.com/tag/软件」这样的 URL 就会发生 404 错误。
像 Godaddy 的 Windows 主机正是使用 IIS7 作为 Web 服务器的,在此空间上使用 WordPress 就会出现以上问题,虽然可以通过修改程序文件或者修改 Tag 和分类的别名为英文的方法来解决,但非常不实用。
下面介绍一种解决方法,只需要增加一个 PHP 文件,并修改一下 web.config 文件中的 Rewrite 规则即可,不需要修改程序文件。
新建一个“chineseurl.php”文件,内容如下:

<?php
if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
// IIS Mod-Rewrite
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
} else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
// IIS Isapi_Rewrite
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
} else {
// Use ORIG_PATH_INFO if there is no PATH_INFO
(!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'])) {
($_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME']) ? ($_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']) : ($_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']);
}
// Append the query string if it exists and isn't null
(isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) && ($_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']);
}
require("index.php");
?>

修改 web.config 文件内容如下:

?<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
 <rewrite>
 <rules>
 <rule name="cnUrl" stopProcessing="true">
 <match url="^(tag|category)/(.*)$" />
 <action type="Rewrite" url="cnurl.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 的安装目录。
如果 WordPress 不是装在根目录,则需要更改“<match url=”^(tag|category)/(.*)$” />”为“<match url=”^安装目录/(tag|category)/(.*)$” />”。如果在固定链接设置里把默认的标签前缀和分类目录前缀(tag 和 category)改了,则更改这句里的对应内容即可。
此文适用于 WordPress 2.9,2.9以下版本应该也可以适用,但笔者没有测试过。

wordpress搬家到cPanel主机

之前备份了数据库sql文件和整站的文件,考虑已久决定的事情当然早有准备。
搬家过程如下:
1.还原数据库和wordpress文件
登陆cPanel管理页面创建新的数据库
2012-01-16_22-31-37
然后添加mysql用户向刚才建立的数据库添加这个用户,记下用户名和密码,等下要在原先的wordpress的wp-config.php里修改数据库和用户名
2012-01-16_22-33-34
 
之前备份的wordpress文件压缩成rar格式的,结果传到cPanel上不能解压缩,又换成zip格式的传上去解了压缩
2.修改wp-config.php指向新的数据库
找到wp-config.php右击选择Edit
2012-01-16_22-38-00
然后编辑你的数据库配置
2012-01-16_22-39-32
然后就大功告成了,
 
如果你的域名变了的话,就要进mysql里的wp_options表里改下siteurl和host的值
大功告成,搬家成功!