1

在 webapp2 (python) 中,您可以将 url 映射到一个文件中的类。

app = webapp2.WSGIApplication([('/', pgMain), ('/test/', pgTest)], debug=True)

我将如何在 php 和 apache 中设置这样的东西?

谢谢

编辑:

我所追求的是将文件夹名称重定向到该文件夹​​中的文件之后的所有内容。例如。

/version/1.0/test/folder/ => /version/1.0/index.php & var="/test/folder"
/version/1.0/another/     => /version/1.0/index.php & var="/another"

谢谢。

4

1 回答 1

1

执行此操作的最简单方法是在您的应用程序文件夹中创建 .htaccess 文件并将此代码放在那里:

RewriteEngine On
RewriteBase /

RewriteRule "(^|/)\." - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [NC,NS,L]

请注意,您需要修改“RewriteBase”指令并将应用程序的路径放在那里“/”表示您的文档根目录。

创建 .htacess 文件后,所有请求都将被路由到您的 index.php 文件,您可以通过 PHP 的超级全局变量 $_SERVER['REQUEST_URI'] 访问 URI

于 2011-11-16T12:03:04.440 回答