【问题标题】:How to create virtual folders using php?如何使用 php 创建虚拟文件夹?
【发布时间】:2015-08-25 05:40:22
【问题描述】:
我正在将 php 与 aws elasticbeanstalk 一起使用。
我想创建一个接受这个 url 的文件夹:
www.example.com/481818
其中 481818 表示已更改的 id。
所以我想创建一个文件来接受这个结构www.example.com/integer 的每个请求。并获取 id。
我不知道如何创建这个文件。
我可以用这个网址:www.example.com/?id=4545454。但我不想要这个 url 结构。
谢谢
【问题讨论】:
标签:
php
apache
amazon-elastic-beanstalk
php-5.4
【解决方案1】:
您必须将所有不存在的 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>
【解决方案2】:
把这个放在你的.htaccess文件里
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?id=$1 [NC,L]
</IfModule>
它应该做你想要的,我以前没有使用弹性豆茎,希望我能帮助你。