.htaccess定义了php系统的路由

时间:2015-11-10 03:35:41

标签: php .htaccess url-rewriting

我有一个基于php的系统,目前使用此设置

的.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php  
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

PHP

<?php
$route = explode('/',(isset($_GET["route"]))? $_GET["route"]:"home");
...
some other stuff based on route parts
...
$route = implode("/", $route);
... 
#load content
include(includes/$route/index.php);

然后发送并请求路由

domain.net/this/is/the/page => route = this/is/the/page
domain.net/this/page => route = this/page
domain.net/page => route = page

然后从这个php将加载一个文件从包含文件夹,并控制系统的内容。

$route = this/is/the/page => loads => includes/this/is/the/page/index.php
$route = this/page => loads => includes/this/page/index.php
$route = page => loads => includes/page/index.php

等等这对我的系统很有用,但我已经考虑过更加动态地扩展它,所以如果我想要它的动态复制我可以创建一个新的包含文件夹的东西

所以我向StackOverflow的精彩人士提出的问题我怎么能理解这个呢?

domain.net/{copy}/{this/is/the/page}
//would output this
$server = copy;
$route = this/is/the/page

domain.net/{copy2}/{this/page}
//would output this
$server = copy2;
$route = this/is/the/page

domain.net/{copy2}/{this/page}
//would output this
$server = copy2;
$route = this/page    

domain.net/{copy2}/{page}
//would output this
$server = copy2;
$route = page

所以第一个是$ server,之后的所有尾随路径是$ route

domain.net/[server]/[path/to/file]

因此,我可以更轻松地管理具有多个版本的系统。

除此之外,我能想到的只是创建一个新域并将其复制到该域位置,并为客户端进行该版本所需的所有调整。

我真的很生气,或者可以做到这一点。

0 个答案:

没有答案