有没有一种简单的方法可以避免创建所有文件夹
好的,我有这个 site.... 以及网址
http://posnation.com/
,并且有很多页面需要保存网址结构...就像这个
http://posnation.com/restaurant_pos
http://posnation.com/quickservice_pos
http://dev.posnation.com/retail_pos
分机...
我现在遇到的问题是我想为所有这些页面保存相同的网址,并且我正在寻找最好的方法。它现在的工作方式是通过 miva 中的代码完成的,我们正在离开 miva....我知道我可以创建一个名为 Restaurant_pos 的文件夹或任何 url 并在其中创建一个 index.php。这种方法将起作用但问题是我需要为 600 个不同的页面执行此操作,并且我不喜欢以最佳方法创建 600 个文件夹。
任何想法
Ok so I have this site.... with the url
http://posnation.com/
and there are alot of pages that i need to save the url structure for....like this
http://posnation.com/restaurant_pos
http://posnation.com/quickservice_pos
http://dev.posnation.com/retail_pos
ext....
The problem that i have now is that i want to save the same url for all these pages and I am looking for the best approach. The way its working now is its done with a code in miva and we are getting off miva.... I know I can create a folder named restaurant_pos or whatever the url is and create an index.php in there.This approach will work but the problem is I need to do this for 600 different pages and I dont feel like creating 600 folders in the best approach.
any ideas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 .htaccess 将所有请求路由到单个文件(例如 index.php),并根据请求的 URL 从那里执行服务。
服务器根目录上的以下 .htaccess 文件会将所有请求路由到您的 index.php:
现在您应该解析 $_REQUEST['route'] 来确定您应该提供哪个文件。下面是一个基于 URL 最后一个元素(例如:pos)提供页面的示例:
当然,您需要编写自己的逻辑,上面只是一个示例。
希望这有帮助。
You should use .htaccess to route all the requests to a single file, say index.php and do the serving from there based on the requested URL.
The following .htaccess file on the server root will route all the requests to your index.php:
Now you should parse the $_REQUEST['route'] to identify which file you should serve. Here is an example that will serve a page based on the last element of the URL (ex: pos):
Definitely you'll need to write your own logic, the above is just an example.
Hope this helps.
通常,最简单的方法是创建一个 .htaccess 文件,将所有请求重定向到
/index.php
。在/.index.php
中,您可能使用$_SERVER['REQUEST_URI']
分析 URL 并包含适当的内容。这是一个示例 htaccess
在您的
/.index.php
中执行类似...(这只是一个非常简单的示例)现在,如果有人访问
http://posnation.com/restaurant_pos
pages/restaurant_pos.php
将被包含在内。pages/restaurant_pos.php
也可以包含页眉和页脚。Usually the easiest way to do this is to create an .htaccess file that redirects all requests to
/index.php
. In/.index.php
you analyze the URL using probably$_SERVER['REQUEST_URI']
and include the appropriate content.Heres a sample htaccess
In your
/.index.php
do something like ... (this is just a VERY simple example)Now if someone goes to
http://posnation.com/restaurant_pos
pages/restaurant_pos.php
will be included.pages/restaurant_pos.php
could include the header and footer too.