Home php教程 php手册 php系统中实现的url重写/隐藏

php系统中实现的url重写/隐藏

Jun 06, 2016 pm 07:52 PM
php url accomplish system rewrite hide

www.cn-web.com网站大部分地址实现的url重写,因为我写的文章大多与.net技术有关,很多朋友以为这个系统也是基于.net技术的,其实这个系统是基于php+mysql写的,.net技术也可以实现url隐藏,我将在下篇文章中介绍下,今天我说我www.cn-web.com系统中url重写

www.cn-web.com网站大部分地址实现的url重写,因为我写的文章大多与.net技术有关,很多朋友以为这个系统也是基于.net技术的,其实这个系统是基于php+mysql写的,.net技术也可以实现url隐藏,我将在下篇文章中介绍下,今天我说我www.cn-web.com系统中url重写的实现。
--------------------------------------------------------------------------------

核心部分是.htaccess文件,默认可能不支持.htaccess,请查看《apache 不支持.htaccess文件如何处理》。
 
首先我们看下一个地址:
http://www.cn-web.com/cnweb/0/445/article/
这个地址的cnweb其实是虚拟的:

为什么没有cnweb这个目录而虚拟主机又认它呢,这就是因为我设置了.htaccess文件了:
.htaccess文件里加一段配置代码,如下:

 ForceType application/x-httpd-php

这样就完成了第一步了,appach服务器看到地址栏里有cnweb这个目录地址后就把它当为了php的处理方式了;
OK,接着我们在根目录下建立cnweb文件,去掉它的扩展名,也就是没有扩展名,呵呵。这个文件里的代码是用php来写的(因为刚才已经将它注册到了appache服务器了)
可能大家已经想到了,在cnweb里我们就要配置下一步如何来转向了。
为了安全性,我这里不贴出我的cnweb文件的代码了,不过可以举个小例子:
$fields = explode('/', $_SERVER['REQUEST_URI']);
$id_pos = array_search('cnweb', $fields);
if( $id_pos !== false )
{
 $c_id = $fields[ $id_pos + 1 ];
 $a_id = $fields[ $id_pos + 2 ];
}
以上通过分析url取得类别ID和文章ID
if( $a_id )
{
$_GET['aid'] = $a_id;
$_GET['cid'] = $c_id;
require_once('showarticle.php');
}
?>

通过以上文章,大家可以看到,其实我显示文章的页面是'showarticle.php?aid=45&cid=0',当我们打开http://www.cn-web.com/cnweb/0/445/article/这个地址时,自动隐式转向是'showarticle.php?aid=45&cid=0'这个地址。
接下来如何设置处理showarticle.php,大家比我更清楚啦,呵呵。
.大家还可以在cnweb文件里对参数时行安全处理等相关设置,我就不说了,很简单的。

http://www.cn-web.com/cnweb/0/446/article/

 

 

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles