Table of Contents
Apache:如何利用.htaccess文件对PHP网站或文件进行伪静态处理,
Home php教程 php手册 Apache:如何利用.htaccess文件对PHP网站或文件进行伪静态处理,

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

Jun 13, 2016 am 09:22 AM
apache php use deal with how right document website conduct static

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中查找以下部分:

<span><Directory />
   Options FollowSymLinks
   AllowOverride None
</Directory></span>
Copy after login

改为:

<span><Directory />
   Options FollowSymLinks
   AllowOverride All
</Directory></span>
Copy after login

如果没有,手动添加。(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文件如下:

<span>#rewriteengine为重写引擎开关on为开启off为关闭</span><span>
RewriteEngine On 
RewriteRule ^index\.html$ index.php
RewriteRule ^webmore\.html$ webmore.php</span>
Copy after login
   以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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

How to set the cgi directory in apache How to set the cgi directory in apache Apr 13, 2025 pm 01:18 PM

To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

How to start apache How to start apache Apr 13, 2025 pm 01:06 PM

The steps to start Apache are as follows: Install Apache (command: sudo apt-get install apache2 or download it from the official website) Start Apache (Linux: sudo systemctl start apache2; Windows: Right-click the "Apache2.4" service and select "Start") Check whether it has been started (Linux: sudo systemctl status apache2; Windows: Check the status of the "Apache2.4" service in the service manager) Enable boot automatically (optional, Linux: sudo systemctl

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

How to delete more than server names of apache How to delete more than server names of apache Apr 13, 2025 pm 01:09 PM

To delete an extra ServerName directive from Apache, you can take the following steps: Identify and delete the extra ServerName directive. Restart Apache to make the changes take effect. Check the configuration file to verify changes. Test the server to make sure the problem is resolved.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

How to view your apache version How to view your apache version Apr 13, 2025 pm 01:15 PM

There are 3 ways to view the version on the Apache server: via the command line (apachectl -v or apache2ctl -v), check the server status page (http://&lt;server IP or domain name&gt;/server-status), or view the Apache configuration file (ServerVersion: Apache/&lt;version number&gt;).

See all articles