本站有闲置空间

Rewrite 重写

2012-12-25 tomeqiu 技术原创

# typecho 博客适用,其他未知。

一、Apache

<IfModule mod_rewrite.c>
RewriteEngine On
#你的博客目录,可能是/或/blog,用它替换Your_blog_dir,下同
RewriteBase Your_blog_dir
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Your_blog_dir/index.php/$1 [L]
</IfModule>

域名跳转:

# 带www的跳转到不带的
RewriteCond %{HTTP_HOST} ^www.0x84.com$
RewriteRule (.*) http://0x84.com/$1 [R=301,L]

二、Nginx

#1#
location / {
index index.html index.php;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php) {
rewrite (.*) $1/index.php;
}
if (!-f $request_filename) {
#10#
rewrite (.*) /index.php;
}
}

这个有必要说两句,百度搜到的,几乎全是上面所写,那我的博客目录是/blog的话,就不适用了。怎么办?看着:

把上面#1#、#10#行改为

#根据你的博客路径修改
location /blog {
rewrite (.*) /blog/index.php;

域名跳转:

# 不带www的跳转到带的

if ($host ~* (blog\.|^)(0x84\.com)) {
set $without_www $2;
rewrite (.*) http://www.$without_www$1 permanent;
}

三、Lighttpd

# 文章 | 标签 | 分页 | RSS | 分类 | 归档 | 搜索 | 独立页面
url.rewrite = (
"^/(archives|tag|page|feed|category|[0-9]{4}|search|guestBook.html)(|/.*)" => "/index.php/$1$2",
)

域名跳转:

# 不带www的跳转到带的

$HTTP["host"] !~ "^(www\.0x84\.com)$" {
url.redirect = ( "^/(.*)" => "%1/$1" )
}

注:请记得到后台永久链接设置里,启用地址重写功能。

标签: rewrite apache nginx lighttpd typecho

发表评论:

Powered by emlog  数据库调用 6次 加载耗时 20.67mssitemap
Free Web Hosting