zoukankan      html  css  js  c++  java
  • 通过htaccess使用伪静态

    利用htaccess文件可以很好的进行站点伪静态,并且形成的目标地址与真正的静态页面几乎一模一样,如abc.html等,伪静态可以非常好的结合SEO来提高站点的排名,并且也能给人一种稳定的印象。

    若要通过htaccess使用伪静态,则必须空间商支持Rewrite模块,该模块负责URL的重写。否则即便是设置好了,也无法使用,并且还有可能出现500错误。

    PHP检测是否支持Rewrite模块:

            $result = apache_get_modules();
            if(in_array('mod_rewrite', $result)) {
                    echo '支持';
            } else {
                    echo '不支持';
            }

    .htaccess文件常见代码

    ErrorDocument 404 /404.html
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^xxc.com [NC]
    RewriteRule ^(.*)$ http://www.xxc.com/$1 [L,R=301]
    
    RewriteRule ^index.html$ /Index.php [QSA]
    
    ##################################################
    RewriteRule ^ajaxwww.html$ /Index.php?Module=Ajax&Action=Index [QSA]
    #自定义页面START
    RewriteRule ^about/map.html$ /Index.php?Module=About&Action=Map [QSA]
    RewriteRule ^about/([a-z]+).html$ /Index.php?Module=About&Action=Help&Alias=$1 [QSA]
    RewriteRule ^about/([0-9]+).html$ /Index.php?Module=About&Action=HelpInfo&ID=$1 [QSA]
    #自定义页面END
    
    #验证码
    RewriteRule ^code/pic.jpg$ /Plugins/Code/Class.DoCode.php [QSA]
    #SEO
    RewriteRule ^robots.txt$ /robots.php [QSA]
    RewriteRule ^sitemap.xml$ /sitemap.php [QSA]
    
    </IfModule>
    

      

  • 相关阅读:
    一夜风雨,夏入秋
    Starting,博客园的开通,渐行渐远
    The second day
    The first day study
    [前缀和] Jzoj P3913 艰难的选择
    [树形dp] Jzoj P3914 人品问题
    [匈牙利][Floyd] Jzoj P1015 导弹
    [高精度][规律][二分] Jzoj P4213 对你的爱深不见底
    [概率dp] Jzoj P4212 我想大声告诉你
    [最小割][最大流] 洛谷 P1345 奶牛的电信
  • 原文地址:https://www.cnblogs.com/xie-xiao-chao/p/8351854.html
Copyright © 2011-2022 走看看