导航:首页 > 编程语言 > phphtaccess伪静态

phphtaccess伪静态

发布时间:2022-11-30 02:11:51

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

利用.htaccess文件对PHP网站进行伪静态处理要考虑两点:
一.服务器支持伪静态,比如Apache要开启mod_rewrite模块支持
二.利用.htaccess完成伪静态需要根据不同的网站系统进行不同的设置,以下是一些常见系统的.htaccess设定:

01.wordpress:

# BEGIN WordPress
<IfMole mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfMole>

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

② phpstudy伪静态设置该怎么做

1、输入以下命令 cd /alidata/server/nginx/conf/rewrite再输入ll 看看是不是像下面截图的一样。 2、这些就是伪静态规则文件。我们打开phpwind.conf看看。 已经在rewrtie目录下配置了常见程序的伪静态规则。可以直接调用。 3、如果没有就按照程序名.conf的命名方式新建一个配置文件 配置文件搞清楚了,你可能会说好像网站伪静态还是啊。别着急,因为伪静态规则是需要被网站配置文件调用才行的。 4、输入以下命令 cd /alidata/server/nginx/conf/vhosts 进入到网站配置目录 5、打开配置文件 修改好伪静态调用文件 下面测试下我们配置的文件是否正确吧输入 nginx: the configuration file /alidata/server/nginx/conf/nginx.conf syntax is ok nginx: configuration file /alidata/server/nginx/conf/nginx.conf test is successful 如果出现以上两句话就说明配置成功了。下面重启下nginx就可以了。

③ PHP伪静态.htaccess文件中GET参数获取问题

RewriteRule ^action-(\w+).html?(.*?)$ index.php?a=$1$2 [QSA,L]

正则规则裏第一个分组是a的值,后面的是query string的值。这是一个参考,具体可能要根据实际需求做更好的正则匹配。

④ php伪静态设置求教

  1. 在httpd.ini中寻找关键字rewrite。有个load......so的前面的#去掉,这样就开启rewrite支持。记得重启

  2. 可以在站点根目录新建一个.htaccess文件(小技巧,windows是不能建只有后缀名的文件,你可以重命名为.htaccess.按enter就可以了自动变成.htaccess)

  3. 文件内容

    RewriteEngine On

    RewriteBase /

    RewriteRule ^id/([0-9]+) 22.php?id=$1


注:rewrite只是对url进行重写,浏览器请求的url是xx.com/id/动态地址,但经过rewrite之后,即php运行的时候,地址还是xx.com/22.php?id=动态地址,所以做解析url的时候是没有任何变化的,唯一要改的是输出的链接地址要符合rewrite规则,才能看到rewrite效果,不然,你只是能解析这个地址,不代表你站内的链接显示的都是你想要的rewrite地址

⑤ php伪静态怎样写

Apache? 配置里面有没有加载 RewriteMole ?

============

1.测试httpd.conf 里面的配置 是否配置允许重写:
在 .htaccess 后面 随意添加一些字符,然后访问一个页面是否是 500
如果是,说明配置哩的AllowOverride on 设置正确
否则 请在对应的 <Directory />节内 修改 AllowOverride None 为 AllowOverride On

2. .htaccess 文件修改为

#------------- .htaccess ----------------

RewriteEngine On
RewriteBase /
RewriteRule (.*)\.html $1.php

#------------- .htaccess ----------------

完毕~

⑥ IIS 服务器下的PHP伪静态要怎么弄啊

IIS配置支持伪静态 ISAPI Rewrite(win2003系统)

第一:首先我们需要下载一个ISAPI_Rewrite,有精简版和完全版,一般精简版只能对服务器全局进行配置,而完整版可以对服务器上的各个网站进行伪静态配置.对于个人站长来说,精简版就足够了.

下载:http://www.isapirewrite.com/download/isapi_rwl_0055.msi

第二:下载完成后,可以找到安装包里的.msi的文件,安装即可.

随便装在哪都可以,默认是装在C:\Program Files\Helicon下,要注意的是这个目录everyone要有读取权限。我就因为当时服务器权限配的比较严格,默认安装Helicon这目录EVERYONE是没有任何权限的,结果老是出现:Service Unavailable 。

第三:打开Internet 信息服务,右键,web站点属性,点击ISAPI筛选器选项卡.添加筛选器,这里的名称可以自己随意填写,路径自己指定ISAPI_Rewrite.dll,然后确定.

下面我们先做一个测试页new.asp,可以按照下面的代码写

然后,在浏览器中输入:

http://127.0.0.1/new.asp?id=1234

接着你就可以在网页上看到一行文字:"1234"

看到这几个数字,就说明你测试成功了.

现在我们开始来配置ISAPI_Rewrite :

打开ISAPI_Rewrite的目录,把httpd.ini的只读属性去掉,打开编辑.我们现在是需要把new.asp?id=1234修改成类似new_1234.html的路径,因此,我们需要在httpd.ini中添加一句

RewriteRule /new_([0-9,a-z]*).html /new.asp?id={GetProperty(Content)}

保存后,我们就可以测试一下这个网址了:http://127.0.0.1/new_1234.html

可以看到页面上的"1234"了吧,就这样伪静态配置成功了!

⑦ ThinkPHP怎么实现伪静态

1、实现伪静态方法:
1)隐藏入口文件:http://doc.thinkphp.cn/manual/hidden_index.html
2)结合使用URL路由:http://doc.thinkphp.cn/manual/url_route.html
3)配置伪静态后缀名:HTML_FILE_SUFFIX => '';
上面三个都用上,基本都OK了!当然,还可以通过服务器重写URL
2、设置让地址栏不能访问文件夹
1)每个文件夹添加一个index.html空文件(因服务器默认的首页而异同),假如默认首页是 index.html 那就 添加index.html
2)也可以通过服务器配置目录访问权限

⑧ 网站优化之PHPCMS如何开启伪静态

在安装完最新版的PHPCMS V9版后,默认是不启用伪静态的,你需要经过一些设置才能实现。

.htaccess文件
首先第一点,你需要在网站根目录下放置一个“.htaccess”文件,来标明其“Rewrite”规则。这个文件实际在最新版的V9版的readme目录下有,默认跟上传目录分开的,刚才说了,PHPCMS默认是不开启伪静态的。所以,你只需要将其上传到你的根目录即可。当然你也可以自己编写,其内容如下:

RewriteEngineon
RewriteRule^content-([0-9]+)-([0-9]+)-([0-9]+).htmlindex.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3
RewriteRule^show-([0-9]+)-([0-9]+)-([0-9]+).htmlindex.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3
RewriteRule^list-([0-9]+)-([0-9]+).htmlindex.php?m=content&c=index&a=lists&catid=$1&page=$2

栏目管理设置不生成Html
第二步,你需要在你的后台栏目管理里面,对你的各个栏目设置为不生成Html,默认是生成的,请注意。


同时,你还需要选择栏目页和内容页的URL规则如上图所示的规则类型。

一切设置完毕后,更新你的缓存,就完工了!

阅读全文

与phphtaccess伪静态相关的资料

热点内容
特别好玩的解压神器你们想玩吗 浏览:180
加密货币盗窃安全吗 浏览:604
吊死荡秋千的电影叫什么 浏览:830
异常预测算法 浏览:981
armlinuxopencv 浏览:539
李采谭英语老师考90分电影叫什么 浏览:216
韩国吻戏床戏 浏览:611
288w.CC 浏览:159
hbasejava编程 浏览:443
mac怎么帮安卓手机迁移数据 浏览:950
服务器110087什么意思 浏览:72
肉'电影百合 浏览:799
流浪爱侣1984 在哪看 浏览:333
日本大迟度电影排行榜前十名 浏览:386
露生殖电影 浏览:523
中文算法学习网站 浏览:623
银行年报pdf 浏览:494
phpcurl取cookies 浏览:719
马克是什么电影 浏览:496
云服务器回本周期 浏览:803