动态URL重写的.htaccess

编程入门 行业动态 更新时间:2024-10-24 22:29:47
本文介绍了动态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: `example/controller/action/do/value` or `example/$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

本文发布于:2023-11-01 12:04:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   动态   URL   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!