经过htaccess使用伪静态

利用htaccess文件能够很好的进行站点伪静态,而且造成的目标地址与真正的静态页面几乎如出一辙,如abc.html等,伪静态能够很是好的结合SEO来提升站点的排名,而且也能给人一种稳定的印象。php

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

PHP检测是否支持Rewrite模块:ajax

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

.htaccess文件常见代码apache

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>
相关文章
相关标签/搜索