.htaccess 配置

  1. 常规wordpress配置
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # protect xmlrpc
    <Files xmlrpc.php>
        Order Deny,Allow
        Deny from all
    </Files>
    wordpress Code
  2. 使用.htaccess做多语言版本的web
    如 EN / CH
    给"EN"添加PHP链接,点击之后生成Cookie做相应跳转,代码如下
    <?php
      setcookie("C_language","en",time()+31536000,"/"); 
      header("Location: http://www.website.com");
    ?>
    en.php Code

    .htaccess内容如下

    #### Rewrite Browser Germany Language
    RewriteCond %{HTTP_COOKIE} !.*C_language.*     //不存在cookie
    RewriteCond %{HTTP:Accept-Language} ^de [NC]   //浏览器为DE语
    RewriteRule ^$ http://www.website.com/de [R=302,L]   
    
    RewriteCond %{HTTP_COOKIE} ^C_language=de [NC]    //cookie 为de语
    RewriteRule ^$ http://www.website.com/de [R=302,L]
    .htaccess Code

    代码解释:
    初次进入网站,不存在C_language,浏览器为DE语,会打开www.website.com/de/页面
    初次进入网站,不存在C_language,浏览器为EN语,会打开www.website.com
    若用户点击了EN / CN 切换按钮,会生成C_language的Cookie,若Cookie为DE,进入www.website.com/de/页面。反之进入www.website.com
    之后的用户访问均会根据Cookie做相对应的跳转

  3. 下载文件的改写

    A、自身服务器做转换
    RewriteCond %{REQUEST_URI} Download_File_For_.*\.exe$
    RewriteRule Download_File_For_.*\.exe$ File_Setup.exe

    B、跳转到CDN下载服务器做转换
    RewriteCond %{REQUEST_URI} Download_File_For_.*\.exe$
    RewriteRule ^(.*) http://cdn.website.com/$1 [L,R=permanent]
    下载服务器:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule Download_File_For_.*\.exe$ File_Setup.exe

    代码解释
    所有用户下载Download_File_For_***.exe的文件,文件名会是Download_File_For_***.exe,真实的文件确是File_Setup.exe

  4. 保护当前目录,只允许某个IP访问,如保护phpMyAdmin
    order allow,deny
    allow from 10.10.0.1
posted @ 2015-06-10 11:19  Mr黄瑞  阅读(233)  评论(0编辑  收藏  举报