重写的URL参数 - 更改http:// MyWeb即可/部门=部门和放大器;应用=应用到http:// MyWeb即可/部门/应用 [英] Rewrite Url Parameters - Change http://myweb/?dept=dept&app=app to http://myweb/dept/app

查看:105
本文介绍了重写的URL参数 - 更改http:// MyWeb即可/部门=部门和放大器;应用=应用到http:// MyWeb即可/部门/应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在明白了,我需要优化Web应用程序和方法什么的,我想实现的是这样的:

I've currently got a web application that I need optimizing, and one of methods or something I'm trying to achieve is such:

的http:// MyWeb即可/部门/应用

的http:// MyWeb即可/部门=部门和放大器;应用程序=应用

我目前已经将此作为PHP code吧:

I've currently this as the PHP code for it:

if(empty($_REQUEST['dept'])) {     
 $folder = "apps/"; 
} else {    
 $folder = str_replace("/", "", $_REQUEST['dept']) . "/"; }    
  if(empty($_REQUEST['n'])) {     
     include('user/home.php'); 
	 } else {     
	       $app = $_REQUEST['n'];
	      if(file_exists($folder.$app.".php")) {          
			 include($folder.$app.".php");     
			 } else  {  				 
			 include("global/error/404.php");    
			 }
		 }

我如何做到这一点?

How do I do this?

我目前一半有:

RewriteRule ^([A-Za-z]+)$ /index.php?app=$1

但只有重写它的一部分。

but that only rewrites part of it.

感谢

推荐答案

的方式很多框架做,这是与下列规则:

The way many frameworks do this is with one of the following rules:

RewriteRule ^(.*)$ /index.php?q=$1
RewriteRule ^(.*)$ /index.php

在第一种情况你在$ _GET [Q]查询字符串。

在第二种情况,你必须获得$ _REQUEST什么的查询字符串。 (只是做一些var_dumps直到你找到你所需要的)。

然后你爆炸(/)这一点,就这么简单。

In the 1st case you get the query string in $_GET["q"].
In the 2nd case you have to get the query string from $_REQUEST or something. (just do some var_dumps till you find what you need).
Then you explode("/") this and you're all set.

看一看如何 TYPO3 ,的 eZPublish 的Drupal 做到这一点。

Have a look at how TYPO3, eZPublish, Drupal do this.

您还应该添加下列条件允许网站打开你的静态文件(如图像/ CSS / JS /等)。他们告诉Apache不行,URL指向的重写实际相匹配的文件,directoy或符号链接的位置。 (您必须RewriteRule指令之前做到这一点)

You should also add the following conditions to allow the site to open your static files (like images/css/js/etc). They tell apache to not do the rewrite if the URL points to a location that actually matches a file, directoy or symlink. (You must do this before the RewriteRule directive)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

这篇关于重写的URL参数 - 更改http:// MyWeb即可/部门=部门和放大器;应用=应用到http:// MyWeb即可/部门/应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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