如何使用 php 创建虚拟文件夹


How to create virtual folders using php?

我正在使用带有aws elasticbeanstalk的php。我想创建接受此网址的文件夹:

www.example.com/481818

其中481818显示已更改的 ID。

所以我想创建接受此结构的每个请求的文件 www.example.com/integer. 并获取 ID。

我不知道如何创建此文件。

我可以用这个网址来做到这一点:www.example.com/?id=4545454 . 但我不想要这个网址结构。

谢谢

您必须将所有不存在的 URL 重写为脚本。在 Apache 上,您可以将这些规则添加到 www 根目录中.htaccess文件中。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ /index.php?id=$1 [L]
</IfModule>
把它

放在你的.htaccess文件中

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^([0-9]+)$ index.php?id=$1 [NC,L]
</IfModule>

它应该做你想做的事,我以前没有使用弹性豆茎,希望我能帮到你。