我一直有一个相当标准的apache配置。现在,我们正在引入一个新概念,即特定于用户会话的URL,这将改变事情。基本上,我们有一个DocumentRoot和诸如以下内容的内容:
http://example.com/
将在DocumentRoot
指令中.html命中索引。
但现在我希望能够做一些类似的事情
http://example.com/uid/5/
http://example.com/uid/2
这些仍应命中索引.html在已设置的 DocumentRoot 中。URL 主要用于服务器端和客户端脚本,以便能够执行自己的任务。
在 Apache 中处理这个问题的最佳方式是什么?这里甚至有必要mod_rewrite吗?
我还需要能够支持现有路径,例如:
http://example.com/foo/bar/something.php
将被重写为http://example.com/uid/3/foo/bar/something.php
但仍会像以前一样到达文件系统上的相同位置。
将此代码放入htaccess中使用mod_rewrite
RewriteEngine On
RewriteRule ^uid/([1-9][0-9]*)/(.+)$ /$2?uid=$1 [L]
例:
http://example.com/foo/bar/something.php ->不变
http://example.com/uid/3/foo/bar/something.php ->重写为/foo/bar/something.php?uid=3
编辑:没有附加 uid
RewriteEngine On
RewriteRule ^uid/[1-9][0-9]*/(.+)$ /$1 [L]