Apache:如何利用.htaccess文件对PHP网站或文件进行伪静态处理
来源:http://www.ido321.com/1123.html
今天get了一招:利用.htaccess文件对PHP网站或文件进行伪静态处理。
一、检查服务器是否支持伪静态处理:
必须要空间支持 Rewrite 以及对站点目录中有 .htaccess 的文件解析,才有效.找到apache安装目录下的httpd.cof文件,去掉LoadModule rewrite_module modules/mod_rewrite.so前面的#(大概在154行,我的默认是开启)
二、在httpd.cof中查找以下部分:
<directory></directory> Options FollowSymLinks AllowOverride None
改为:
<directory></directory> Options FollowSymLinks AllowOverride All
如果没有,手动添加。(PS:LZ试过,在最近的新版本的Apache上即使没有这个,.htaccess照样生效。但是不同服务器及版本的原因,建议加上)
三、重启apache服务器,添加.htaccess文件
建立.htaccess文件的方式:
1、保存文件的时候将文档保存成名为“***.txt”,再将其上传到服务器上,之后直接使用FTP软件来重命名为“.htaccess”。(适合windows)
2、保存文件的时候选择文件?>另存为,保存类型选所有文件,然后文件名输入.htaccess 。(适合windows)
3、直接在你的Unix或Linux虚拟主机上建立。
4、先用记事本编写好,随便保存为一个什么文件名,然后打开“命令提示符”(CMD),然后再用重命名命令(rename),例如:rename c:\htaccess.txt .htaccess
请注意: .htaccess必须,保存为ANSI 格式,以ASCII模式上传,最好将其权限设置为644。
一般我们将.htaccess文件放置在网站的根目录,控制所在目录及所有子目录,当然也可以放在网站的任何一个子目录下,但如果放置在子目录中,子目录中的指令会覆盖更高级目录或者主服务器配置文件中的指令。
在博客收录集(http://www.ido321.com/1112.html)为例,本地.htaccess文件如下:
#rewriteengine为重写引擎开关on为开启off为关闭RewriteEngine On RewriteRule ^index\.html$ index.phpRewriteRule ^webmore\.html$ webmore.php
以index.html代替index.php webmore.html代替webmore.php。
.htaccess支持正则表达式,例如:
原始 news/detail.php?id=2 伪静态 news/detail_2.html
RewriteRule ^news/detail_([0-9]{1,})\.html$ news/detail.php?id=$1
下一篇:杂谈:HTML 5页面可视性API

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
