如何利用.htaccess文件对PHP网站或文件进行伪静态处理

如何利用.htaccess文件对PHP网站或文件进行伪静态处理,第1张

利用.htaccess文件对PHP网站进行伪静态处理要考虑两点:

一.服务器支持伪静态,比如Apache要开启mod_rewrite模块支持

二.利用.htaccess完成伪静态需要根据不同的网站系统进行不同的设置,以下是一些常见系统的.htaccess设定:

01.wordpress:

# BEGIN 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>

02.Phpwind

RewriteEngine On

RewriteBase /

RewriteRule ^(.*)-htm-(.*)$ $1.php?$2

RewriteRule ^(.*)simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2

03.Discuz

RewriteEngine On

# Rewrite 系统规则请勿修改

RewriteRule ^archiver/((fid|tid)-[0-9]+\.html)$ archiver/index.php?$1

RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2

RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2

RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2

RewriteRule ^tag-(.+)\.html$ tag.php?name=$1

04.ecshop

RewriteEngine On

# 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]

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

RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2&page=$3 [QSA,L]

RewriteRule ^brand-([0-9]+)-c([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2 [QSA,L]

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

RewriteRule ^tag-(.*)\.html search\.php\?keywords=$1 [QSA,L]

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

RewriteRule ^group_buy-([0-9]+)\.html$ group_buy\.php\?act=view&id=$1 [QSA,L]

RewriteRule ^auction-([0-9]+)\.html$ auction\.php\?act=view&id=$1 [QSA,L]

05.phpcms

RewriteEngine On

RewriteRule ^(.*)content-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=

$3&page=$4

RewriteRule ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=

$3&page=$4

RewriteRule ^(.*)list-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=lists&catid=$2&page=$3

1、后台设置emlog伪静态规则右上方设置-SEO设置-选择文件形式,如果可以那恭喜,如果打开都404了,那就创建新的规则文件吧。

2、创建emlog伪静态规则文件

后台设置打开错误说明空间不支持.htaccess解析,而是支持httpd.ini 文件的解析。复制下面代码到txt,然后重命名为httpd.ini上传到根目录即可,在DZ伪静态时也是同样问题。下面给出的是最完整的的规则,官方关于此问题详细贴:http://bbs.emlog.net/thread-12483-1-1.html

 [ISAPI_Rewrite]

    # 3600 = 1 hour

    CacheClockRate 3600

    RepeatLimit 32

    RewriteRule /sitemap.xml /sitemap.xml [L]

    RewriteRule /photos/(.*) /photos/$1 [L]

    RewriteRule /rss.php(.*) /rss.php$1 [L]

    RewriteRule /tb.php(.*) /tb.php$1 [L]

    RewriteRule /favicon.ico /favicon.ico [L]

    RewriteRule /xmlrpc.php(.*) /xmlrpc.php$1 [L]

    RewriteRule /wlwmanifest.xml /wlwmanifest.xml [L]

    RewriteRule /(t|m)$ /$1/ [R]

    RewriteRule /(admin|content|include|t|m)/(.*) /$1/$2 [L]

    RewriteRule /install.php(.*) /install.php$1 [L]

    RewriteRule /emlog_toolkit.php(.*) /emlog_toolkit.php$1 [L]

    RewriteRule /up(\d.\d.\d)to(\d.\d.\d).php(.*) /up$1to$2.php$3 [L]

    RewriteRule ^/$ /index.php [L]

    RewriteRule /(.*) /index.php/$1 [L]

3、用emlog伪静态插件

插件地址及说明:http://www.emlog.net/plugin/134。


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/481167.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-06-08
下一篇2023-06-08

发表评论

登录后才能评论

评论列表(0条)

    保存