如何使用虚拟文件夹结构 url

How to use virtual folder structure url

我有url这样

http://www.abcdef.com/somthing.php

我想使用相同的文件内容但不同的 url 格式,就像这样

http://www.abcdef.com/exp/go/to/123

为此我需要修改 php 或 htaccess 文件?

.htaccess 文件

对于您的示例,您将使用:

RewriteEngine on
Redirect ^/exp/go/to/123$ /somthing.php [L]

您使用“/exp/go/to/123”URL 结构的主要原因是不同的元素可以用作加载页面的变量,在这种情况下您可以使用:

RewriteEngine on
Redirect ^/exp/go/to/([0-9]+)$ /somthing.php:id= [L]

这将从 url 中取出 123 并将其作为 ID 参数传递给 someting.php。