当前位置:首页 » 编程语言 » phprewriterule

phprewriterule

发布时间: 2022-06-08 23:15:21

php本地如何实现伪静态页面

Apache的 mod_rewrite是比较强大的,在进行网站建设时,可以通过这个模块来实现伪静态。
主要步骤如下: 1.检测Apache是否开启mod_rewrite功能 可以通过php提供的phpinfo()函数查看环境配置,找到“Loaded Moles”,其中列出了所有apache2handler已经开启的模块,如果里面包括“mod_rewrite”,则已经支持,不再需要继续设置。如果没有开启“mod_rewrite”,则打开目录 apache目录下的“/apache/conf/” ,找到 httpd.conf 文件,再找到“LoadMole rewrite_mole”,将前面的”#”号删除即表示取用该功能。 如果没有查找到“LoadMole” 区域,可以在最后一行加入“LoadMole rewrite_mole ,moles/mod_rewrite.so”(独占一行),之后重启apache服务器。再通过phpinfo()函数查看环境配置就有“mod_rewrite”为项了.。
2.让apache服务器支持.htaccess 如何让自己的本地APACHE服务器支持:“htaccess”呢? 只需修改apache的httpd.conf设置就可以让 APACHE支持“.htaccess”了。打开 APACHE目录的CONF目录下的httpd.conf文件,找到: Options FollowSymLinks AllowOverride None 改为 Options FollowSymLinks AllowOverride All 就行了。
3.建立.htaccess 文件 建立.htaccess文件时要注意,不能直接建,方法是通过记事本中的另存为菜单,在文件名窗口输入:“.htaccess”,然后点击保存。
4.rewrite规则学习 在新建.htaccess文件之后,就在里面写入以下内容: RewriteEngine on #rewriteengine为重写引擎开关on为开启off为关闭 RewriteRule ([0-9]{1,})$index.php?id=$1 在这里,RewriteRule是重写规则,是用正则表达式的句子,([0-9]{1,})表示由数字组成的,$表示结束标志,表示以数字结束!如果要实现伪静态页面,规则如下: RewriteEngine on RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$index.php?action=$1&id=$2 在为个正则表达式中,([a-zA-Z]{1,})-([0-9]{1,}).html$是规则,index.php?action=$1&id=$2是要替换的格式,$1代表第1括号匹配的值,$2代表第二个括号的值,如此类推! 测试PHP脚本如下: index.php文件中的代码如下: echo ‘你的Action值为:’ . $_GET['action']; echo ‘ ’; echo ‘ID值为:’ . $_GET['id']; ?>
在浏览器地址栏输入: localhost/page-18.html 输出的是: 你的Action值为:page ID值为:18

⑵ PHP 伪静态 问题 指向错误

只要支持伪静态的,而且从来没出现过不能访问的情况,除非下面的代码写错了,我是这样子做的
RewriteRule taoou/proct-([0-9]+)\.html$ taoou/proct.php?bid=$1
RewriteRule taoou/proct-([\w]+)-([0-9a-z]+)\.html$ taoou/proct.php?bname=$1&bid=$2
RewriteRule taoou/proct-([\w]+)-([0-9a-z]+)-([0-9]+)\.html$ taoou/proct.php?bname=$1&bid=$2&page=$3
RewriteRule taoou/proct2.html$ taoou/proct2.php
RewriteRule taoou/proct2-([0-9]+)\.html$ taoou/proct2.php?bid=$1
RewriteRule taoou/proct2-([\w]+)-([0-9a-z]+)\.html$ taoou/proct2.php?bname=$1&bid=$2
RewriteRule taoou/proct2-([\w]+)-([0-9a-z]+)-([0-9]+)\.html$ taoou/proct2.php?bname=$1&bid=$2&page=$3
RewriteRule taoou/search.html$ taoou/search.php
RewriteRule taoou/search-([\w]+)\.html$ taoou/search.php?keyword=$1
RewriteRule taoou/search-([\w]+)-([0-9]+)\.html$ taoou/search.php?keyword=$1&page=$2

⑶ PHP编程如何通过Apache开启URLRewrite(转)

检测Apache是否支持mod_rewrite 通过php提供的phpinfo()函数查看环境配置,通过Ctrl+F查找到“Loaded Moles”,其中列出了所有apache2handler已经开启的模块,如果里面包括“mod_rewrite”,则已经支持,不再需要继续设置。 如果没有开启“mod_rewrite”,则打开目录 您的apache安装目录“/apache/conf/” 下的 httpd.conf 文件,通过Ctrl+F查找到“LoadMole rewrite_mole”,将前面的”#”号删除即可。 如果没有查找到,则到“LoadMole” 区域,在最后一行加入“LoadMole rewrite_mole moles/mod_rewrite.so”(必选独占一行),然后重启apache服务器即可。 让apache服务器支持.htaccess AllowOverride None改为Options FollowSymLinks AllowOverride All 就可以了。 建立.htaccess 文件 (1)用记事本打开,点击文件–另存为,在文件名窗口输入”.htaccess”,注意是整个绿色部分,也就是包含英文引号,然后点击保存就行了。 (2)进入cmd命令 窗口,通过cd切换当刚建立htaccess.txt文件的文件夹,然后输入命令:rename htaccess.txt .htaccess ,然后点击键盘Enter键即可。 (3)通过ftp连接htaccess.txt所在文件夹,通过ftp软件重命名。 rewrite规则学习 我们新建一个.htaccess文件之后,就在里面写入以下内容: RewriteEngine on #rewriteengine为重写引擎开关on为开启off为关闭 RewriteRule ([0-9]{1,})$ index.php?id=$1 我讲解一下RewriteRule:RewriteRule是重写规则,支持正则表达式的,上面的([0-9]{1,})是指由数字组成的,$是结束标志,说明是以数字结束! 好吧,现在我们可以实现伪静态页面了,写下一下的规则: <IfMole mod_rewrite.c> RewriteEngine on RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2 </IfMole> ([a-zA-Z]{1,})-([0-9]{1,}).html$是规则,index.php?action=$1&id=$2是要替换的格式,$1代表第一个括号匹配的值,$2代表第二个,如此类推!! 我们写一个处理的PHP脚本:index.phpPHP代码<?phpecho ‘你的Action是:’ . $_GET['action']; echo ‘<br/>’; echo ‘你的ID是:’ . $_GET['id'];?>好了,我们现在在浏览器中输入: localhost/view-12.html输出的是:你的Action是:view

⑷ php怎么打开重写 php重写URL的教程

1. 找到apache的安装目录下的conf下的httpd.conf文件,打开文件修改
LoadMole rewrite_mole moles/mod_rewrite.so这行代码,他前面有个#号,把#号删掉
2. 还是那个文件,打开,找到
代码如下 复制代码
<Directory />
Options FollowSymLinks ExecCGI Indexes
AllowOverride None
Order deny,allow
Deny from all
Satisfy all
</Directory>
这个节点,把None改为All. 3. 重启apache服务
4. 最关键的一点,在你得项目目录下创建.htaccess文件,文件没有名称,看上去只是后缀名
具体创建方法不能直接创建,先创建个txt文件(其他的也行),然后另存问,把名字改为.htaccess,并且选所有文件,创建好后,就要制定规则了。 在文件里写代码:
RewriteEngine on //on为打开,off为关闭
RewriteRule ([a-zA-Z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2
([a-zA-Z]{1,})-([0-9]{1,}).html$是规则,index.php?action=$1&id=$2是要替换的格式,$1代表第一个括号匹配的值,$2代表第二个,如此类推!

⑸ php伪静态修改后页面是空白

这里我配置的,已经可以使用了,你看下是不是用我的方法
RewriteEngine On
RewriteRule taoou/index.html$ taoou/index.php
RewriteRule taoou/gallery.html$ taoou/gallery.php
RewriteRule taoou/why-choose-us.html$ taoou/why-choose-us.php
RewriteRule taoou/how-to-order.html$ taoou/how-to-order.php
RewriteRule taoou/faq.html$ taoou/faq.php
RewriteRule taoou/contact-us.html$ taoou/contact-us.php
RewriteRule taoou/proct.html$ taoou/proct.php
RewriteRule taoou/proct-([0-9]+)\.html$ taoou/proct.php?bid=$1
RewriteRule taoou/proct-([\w]+)-([0-9a-z]+)\.html$ taoou/proct.php?bname=$1&bid=$2
RewriteRule taoou/proct-([\w]+)-([0-9a-z]+)-([0-9]+)\.html$ taoou/proct.php?bname=$1&bid=$2&page=$3
RewriteRule taoou/proct2.html$ taoou/proct2.php
RewriteRule taoou/proct2-([0-9]+)\.html$ taoou/proct2.php?bid=$1
RewriteRule taoou/proct2-([\w]+)-([0-9a-z]+)\.html$ taoou/proct2.php?bname=$1&bid=$2
RewriteRule taoou/proct2-([\w]+)-([0-9a-z]+)-([0-9]+)\.html$ taoou/proct2.php?bname=$1&bid=$2&page=$3

RewriteRule taoou/search.html$ taoou/search.php
RewriteRule taoou/search-([\w]+)\.html$ taoou/search.php?keyword=$1
RewriteRule taoou/search-([\w]+)-([0-9]+)\.html$ taoou/search.php?keyword=$1&page=$2
RewriteRule taoou/keywords.html$ taoou/keywords.php

RewriteRule taoou/advanced_search.html$ taoou/advanced_search.php

RewriteRule taoou/pinfo-([\w.]+)-([0-9]+)\.html$ taoou/pro-info.php?title=$1&id=$2
RewriteRule taoou/change_currency.html$ taoou/change_currency.php
RewriteRule taoou/shopping-cart.html$ taoou/shopping-cart.php
RewriteRule taoou/cart.html$ taoou/cart.php
RewriteRule taoou/myorder.html$ taoou/myorder.php
RewriteRule taoou/myorder-([0-9]+)\.html$ taoou/myorder.php?page=$1

RewriteRule taoou/a-([\w]+)-([0-9a-z]+)\.html$ taoou/about.php?t=$1&id=$2
RewriteRule taoou/i-([\w]+)-([0-9a-z]+)\.html$ taoou/information.php?t=$1&id=$2
RewriteRule taoou/s-([\w]+)-([0-9a-z]+)\.html$ taoou/service.php?t=$1&id=$2
RewriteRule kaike-info-([0-9]+)\.html$ kaike_info.php?nid=$1

RewriteRule taoou/site-map.html$ taoou/site-map.php

RewriteRule taoou/customer-testimonial.html$ taoou/customer-testimonial.php
RewriteRule taoou/customer-testimonial-([0-9]+)\.html$ taoou/customer-testimonial.php?page=$1

RewriteRule taoou/customer.html$ taoou/customer.php

RewriteRule taoou/links.html$ taoou/links.php
RewriteRule taoou/links-([0-9]+)\.html$ taoou/links.php?page=$1

⑹ 关于PHP urlrewrite的问题

这个可以不用Rewrite实现的。

例如URL为:http://www.abc.com/?XYZ

你要获取XYZ,应该在index.php文件中这样写:

$id=$_SERVER['QUERY_STRING'];
//$id就是获取到的值

//如果要获取纯整数,请使用下面的代码
$id=(int)$_SERVER['QUERY_STRING'];

解释一下:$_SERVER['QUERY_STRING']就是URL中问号(?)后的内容。

这样就可以了。

热点内容
加密视频怎么解密 发布:2024-05-17 11:02:52 浏览:570
柳工挖机密码多少合适 发布:2024-05-17 11:00:40 浏览:187
android工程叹号 发布:2024-05-17 10:56:21 浏览:480
在苹果手机应用怎么比安卓贵 发布:2024-05-17 10:56:20 浏览:547
赛欧313配置怎么样 发布:2024-05-17 10:43:16 浏览:988
c语言预算 发布:2024-05-17 10:43:16 浏览:492
推荐对称加密算法 发布:2024-05-17 10:43:15 浏览:822
有存储功能计算器 发布:2024-05-17 10:42:34 浏览:118
小米账号密码保险箱在哪里 发布:2024-05-17 10:17:00 浏览:752
抖音引流脚本推荐 发布:2024-05-17 10:11:16 浏览:724