PHP如何实现网址伪静态
Apache的 mod_rewrite是比较强大的,在进行网站建设时,可以通过这个模块来实现伪静态。
主要步骤如下:
1.检测Apache是否开启mod_rewrite功能 可以通过php提供的phpinfo()函数查看环境配置,找到“Loaded Modules”,其中列出了所有apache2handler已经开启的模块,如果里面包括“mod_rewrite”,则已经支持,不再需要继续设置。如果没有开启“mod_rewrite”,则打开目录 apache目录下的“/apache/conf/” ,找到 httpd.conf 文件,再找到“LoadModule rewrite_module”,将前面的”#”号删除即表示取用该功能。 如果没有查找到“LoadModule” 区域,可以在最后一行加入“LoadModule rewrite_module ,modules/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
呵呵,改写成功!
下面将我自己配置伪静态的一些个人经验分享一下:
开始接触伪静态,看着很神奇,以为很难,其实很简单,就是在服务器中多配置几个虚拟域名,类似真正的访问网址。 只需三步
A.首先 在Apache Apache模块中,开启 vhost_alias_moudle
B.修改httpd.conf文件,在这个文件中,搜索rewrite .找到 LoadModule rewrite_module modules/mod_rewrite.so 去掉前面的#
C.修改这个文件,在路径 D:\wamp\bin\apache\Apache2.2.21\conf\extra 下的httpd-vhosts.conf 文件,照着示例加一个就OK了
ServerAdmin [email protected]
DocumentRoot "d:/wamp/www/dz"
ServerName localhost.www.dz.cn
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
D.在路径 C:\Windows\System32\drivers\etc 下 的 hosts 文件中配置一下
127.0.0.1 localhost.www.dz.cn 重启服务即可。 大功告成!
**************************************************************************** 大家新年快乐!
注明:在浏览器输入中 localhost.www.dz.cn,即可访问,我加一个localhost是为了和正式的网址加以区别。有不懂的可以QQ:1024900614联系我,方便大家一起探讨,共同进步!
你的伪静态规则全部写在 .htaccess 文件中,由于已经开启了伪静态,会默认加载该文件。 写这个.htaccess 文件 要会写正则哦,学习一些正则基础吧!
- 1楼选择了就坚持
- 学习了,感谢作者! (来源:合仔茶端)

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools
