如何使用目录名作为选项或参数? [英] How to use directory names as options or parameters?

查看:103
本文介绍了如何使用目录名作为选项或参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我甚至不知道如何调用该方法,我只知道我要实现的行为。

我的这个例子是Facebook的。如果你去 facebook.com/ [用户名或ID] 你的个人资料页,但我无法想象,他们正在创造自己的根文件夹的目录并把一个索引文件在那里为每一位用户。

那么,如何的以下行为来实现;你去的 somepage.com/foo/bar/hello 的,但实际上你要求的 somepage.com /富?巴=你好 的?

这甚至可能与Apache和PHP?


解决方案

  

我甚至不知道如何调用该方法,我只知道我要实现的行为。


这件事被称为URI / URL和它的本地部分传递到Web服务器。 Web服务器然后处理请求。


  

这甚至可能与Apache和PHP?


是的。甚至连。这是一个网络服务器是什么。会发生什么事,在服务器上由只知道URI / URL规范是否以及如何需要匹配web服务器上的具体进程或文件不规范的HTTP协议完全屏蔽。

例如与Apache HTTP服务器有一个名为一个著名的模块mod_rewrite的,做URL重写。通常,在一个时尚与她的浏览器用户不采取任何通知。

实例配置与PHP文件(apache httpd的):

 < IfModule mod_rewrite.c>
    RewriteEngine叙述在
    的RewriteCond%{} REQUEST_FILENAME!-f
    重写规则^(。*)$ app.php [QSA,L]
< / IfModule>

在PHP脚本,你可以通过使用特殊变量像的 $ _ SERVER ['REQUEST_URI'] $ _ SERVER ['QUERY_STRING']

I don't even know how this method is called, I just know the behavior I want to achieve.

My example for this is Facebook. If you go to facebook.com/[username or id] you get to the profile page, but I can't imagine that they're creating a directory in their root folder and putting a index file in there for every user.

So how's the following behavior accomplished; You go to somepage.com/foo/bar/hello but actually you're requesting somepage.com/foo?bar=hello ?

Is this even possible with Apache and PHP?

解决方案

I don't even know how this method is called, I just know the behavior I want to achieve.

That thing is called URI/URL and the local part of it is passed to a webserver. The webserver then processes the request.

Is this even possible with Apache and PHP?

Yes. Not even even. This is what a webserver is for. What happens on the server is entirely shielded by the HTTP protocol which knows only the URI/URL specification which does not regulate if and how that needs to match to concrete processes or files on the webserver.

For example with the Apache HTTP Server there is a famous module called Mod_Rewrite that does URL-Rewriting. Often in a fashion that the user with her browser does not take any notice of it.

Example configuration with a PHP file (Apache HTTPD):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

In a PHP script you can obtain the URI/URL by making use of special variables like $_SERVER['REQUEST_URI'] and $_SERVER['QUERY_STRING'].

这篇关于如何使用目录名作为选项或参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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