LINUX虚拟主机实现URL重写

十月 31, 2008 by zuo
日志类别:网络技术 

        今天配置一台Linux服务器里的一个虚拟主机实现了URL重写,使得这个虚拟主机的网站可以实现生成静态HTML网页,有利于搜索引擎收录!

        在网上发现很多人配置URL重写使得服务器支持生成静态HTML网页失败,特此把我的配置过程说一下,其实配置起来还是很简单的!服务器环境:Linux+Apache+Mysql+PHP

第一步:登陆Linux服务器,准备编辑httpd.conf

vi httpd.conf

:o

i

第二步:因为是虚拟主机,增加如下内容:

 <Directory /VirtualhostDocumentRoot>
    Options FollowSymLinks
    AllowOverride All
    order deny,allow
    Allow from all
</Directory>

第三步:退出编辑状态,保存修改,重启Apache

ESC

:wq!

/ApacheServerRoot/bin/apachectl restart

第四步:VirtualhostDocumentRoot中放置.htaccess文本文件,根据本身网站系统的PHP文件类型的不同,该文件各有不同,内容形式大致如下:

<FilesMatch “\.(bak|inc|lib|sh|tpl|lbi|dwt)$”>
    order deny,allow
    deny from all
</FilesMatch>

RewriteEngine On
RewriteBase /

# direct one-word access
RewriteRule ^index\.html$    index\.php [L]
RewriteRule ^category$      index\.php [L]

# access any object by its numeric identifier
RewriteRule ^feed-c([0-9]+)\.xml$       feed\.php\?cat=$1 [L]
RewriteRule ^feed-b([0-9]+)\.xml$       feed\.php\?brand=$1 [L]
RewriteRule ^feed\.xml$                 feed\.php [L]

RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$  category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$                            category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$                                      category\.php\?id=$1&brand=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$                                                       category\.php\?id=$1&brand=$2&page=$3  [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)(.*)\.html$                                                                category\.php\?id=$1&brand=$2  [QSA,L]
RewriteRule ^category-([0-9]+)(.*)\.html$                                                                          category\.php\?id=$1  [QSA,L]

RewriteRule ^goods-([0-9]+)(.*)\.html$  goods\.php\?id=$1 [QSA,L]

RewriteRule ^article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$  article_cat\.php\?id=$1&page=$2&sort=$3&order=$4  [QSA,L]
RewriteRule ^article_cat-([0-9]+)-([0-9]+)(.*)\.html$                   article_cat\.php\?id=$1&page=$2   [QSA,L]
RewriteRule ^article_cat-([0-9]+)(.*)\.html$                            article_cat\.php\?id=$1   [QSA,L]

RewriteRule ^article-([0-9]+)(.*)\.html$                                article\.php\?id=$1   [QSA,L]

第五步:配置网站开启URL重写功能,完成!

相关内容:

  1. apache配置文件httpd.conf中文完整翻译
  2. 31个用来测试你网站各项性能的免费在线工具
  3. PHP安全模式详解
  4. 全程指导Linux 下PHP环境配置 LAMP
  5. 全程指导Windows下PHP环境配置 WAMP
  6. Joomla模板开发指南
  7. Can’t connect to local MySQL server through socket
  8. Windows 2003 建站技术 第二部分
  9. MYSQL数据索引文件的修复方法
  10. 开源CMS作者或爱好者必备程序和技术

评论

使用 gravatar 网络头像

登录 后发表评论!