首页

Categories

Archives

一些mod_rewrite的例子

防止图片或文件被链接

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://206.130.123.198 [NC]
RewriteRule ^.*$ http://www.domain.com/ [R,L]

如果用户的链接不是从www.domain.com,domain.com或206.130.123.198(你的IP地址)来的,就会被转到www.domain.com

将不同的域名格式转向到统一的格式

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]

如果用户使用http://domain.com/yourpage.html将被转到http://www.domain.com/yourpage.html

针对不同的浏览器

# MS Internet Explorer - Mozilla v4
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4(.*)MSIE
RewriteRule ^index\.html$ /index.IE.html [L]

# Netscape v6.+ - Mozilla v5
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/5(.*)Gecko
RewriteRule ^index\.html$ /index.NS5.html [L]

# Lynx or Mozilla v1/2
RewriteCond %{HTTP_USER_AGENT} ^Lynx/ [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12]
RewriteRule ^index\.html$ /index.20.html [L]

# All other browsers
RewriteRule ^index\.html$ /index.32.html [L]

使用不同的浏览器的用户被转向到不同的页面

[tags]mod_rewrite,redirect[/tags]

  • 如何将动态的网址(URL)转换成静态的网址?
  • 如何使搜索引擎收录你的所有网页?搜索引擎优化SEO系列
  • 利用mod_rewrite将动态网页转换为静态的网页
  • Comments (One comment)

    There are no comments for this post so far.

    Post a comment