王新阳

wangxinyang

我的.htaccess

RewriteEngine On
#以old开头的请求301跳转到www.XXX.com首页
RewriteCond %{request_uri} ^/old [NC]
RewriteRule ^(.*)$ http://www.XXX.com/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(robots\.txt|favicon\.ico)$
RewriteCond $1 !^.+\.(ico|js|css|jpg|jpe|jpeg|png|bmp|gif|mp4|flv|swf|txt|pdf|zip|rar|htm|doc|docx|xls|xlsx)$
#部分IIS中!-f无效,需要下面一行以防止手机站被index.php解析
RewriteCond $1 !^m\.php
RewriteRule ^(.*)$ index.php/$1 [L]

允许跨域

Header add Access-Control-Allow-Origin "http://aaa.example"

中文-未验证

RewriteRule ([\x80-\xffa-zA-Z]{1,})-([0-9]{1,}).html$ test.php?action=$1&id=$2

根据域名跳转,下面把abc.com的所有访问临时跳转到def.com(含querystring)

Rewritecond %{HTTP_HOST} ^(www\.)?abc.com$ [NC]
Rewriterule ^(.*)$ http://def.com/$1 [R=302,L]

RewriteCond %{request_uri} ^/old [NC]
RewriteRule ^(.*)$ http://www.XXX.com/ [L,R=301]
以上会把 http://abc.com/old?kw=text 跳转到 http://www.xxx.com/?kw=text
如果要舍弃QUERY_STRING,只需在跳转网址后加问号(正则结尾)即可,如下:
RewriteCond %{request_uri} ^/old [NC]
RewriteRule ^(.*)$ http://www.XXX.com/? [L,R=301]

下面可以用于不支持asp的服务器,把百度收录的原asp网页跳转到指定页面。

RewriteRule ^(.*)\.asp http://www.abc.com/baidu/index/$1 [R=301,L]

nginx伪静态

if (!-e $request_filename) {
	rewrite ^/manage\.php /manage.php last;
	rewrite ^.*$ /index.php last;
}

不是ico/jpg/png/gif中的一种时才进行伪静态重写

location ~* .*(?<!\.(ico|jpg|png|gif))$ {
	if (!-e $request_filename) {
		rewrite ^/manage\.php /manage.php last;
		rewrite ^.*$ /index.php last;
	}
}
2017-08-01
2024-11-24 星期日 农历十月二十四