动态URL重写的.htaccess [英] dynamic URL rewriting .htaccess

查看:149
本文介绍了动态URL重写的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的URL重写,我一直有一些问题,重写我的网址,我有一个单独的.php索引页,其中的内容是使用PHP根据URL变量填充的。

I'm new to URlRewriting and I've been having some problems rewriting my URLs, I have one single .php index page in which the content is filled using php depending on the url variables.

我的问题是,我似乎无法找到正确的EX pressions得到它的工作。 对于我的主页,我只送出1变量如

My problem is that I cannot seem to find the correct expressions to get it working. For my homepage I'm only sending out 1 variable like

"index.php?page=home"

但我使用的其他网页多达4个变量,如index.php页面=大约放大器;含量约 - 新闻和ID = 27&安培; PN = 1

BUT for other pages I'm using up to 4 variables like "index.php?page=about&content=about-news&id=27&pn=1"

现在我得到尽可能获得1或2个工作分开却不能在一起使用:

Now I got as far as getting 1 or 2 working seperately but not together using:

RewriteRule ^((.*)+)$ index.php?page=$1

RewriteRule ^(.*)/(.*)$ index.php?page=$1&content=$2

我一直在四处寻找谷歌和#1,在过去几天,但我似乎无法找到一个有效的解决方案,没有任何人有一个如何得到这个工作任何想法? 干杯

I've been looking around on google and Stackoverflow for the past few days but I cannot seem to find a working solution, does anyone have any ideas of how to get this working? Cheers

推荐答案

所有你需要的是一次重写:

All you need is one rewrite:

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

然后在您的index.php文件的分裂路线为piecies:

then in your index.php file your split the route into piecies:

$route = (!isset($_GET['route']))?'':$_GET['route']);
$parts = explode('/', $route);

So your old urls like this:
index.php?page=home 
index.php?page=about&content=about-news&id=27&pn=1
index.php?page=$1
index.php?page=$1&content=$2

Become:
Example: `http://example.com/controller/action/do/value`
or       `http://example.com/$parts[0]/$parts[1]/$parts[2]/$parts[3]/$parts[4]`

保持到控制器 - >行动 - >做 - >思想价值的简单分配路线。

Keeping to the idea of controller->action->do->value its easy to assign routes.

?页= 将您的控制器

?内容= 将您的操作

ID = 将您的子动作|做|值

这篇关于动态URL重写的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆