有没有一种简单的方法可以避免创建所有文件夹

发布于 2024-11-02 03:06:57 字数 525 浏览 0 评论 0原文

好的,我有这个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江南烟雨〆相思醉 2024-11-09 03:06:57

您应该使用 .htaccess 将所有请求路由到单个文件(例如 index.php),并根据请求的 URL 从那里执行服务。

服务器根目录上的以下 .htaccess 文件会将所有请求路由到您的 index.php:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L]
</IfModule>

现在您应该解析 $_REQUEST['route'] 来确定您应该提供哪个文件。下面是一个基于 URL 最后一个元素(例如:pos)提供页面的示例:

<?php

$parts = explode($_REQUEST['route']);

if ($parts[count($parts) - 1] == 'pos') {
    include "pages/pos.php";
}

当然,您需要编写自己的逻辑,上面只是一个示例。

希望这有帮助。

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:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L]
</IfModule>

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):

<?php

$parts = explode($_REQUEST['route']);

if ($parts[count($parts) - 1] == 'pos') {
    include "pages/pos.php";
}

Definitely you'll need to write your own logic, the above is just an example.

Hope this helps.

谁对谁错谁最难过 2024-11-09 03:06:57

通常,最简单的方法是创建一个 .htaccess 文件,将所有请求重定向到 /index.php。在 /.index.php 中,您可能使用 $_SERVER['REQUEST_URI'] 分析 URL 并包含适当的内容。

这是一个示例 htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

在您的 /.index.php 中执行类似...(这只是一个非常简单的示例)

require 'pages/' . $_SERVER['REQUEST_URI'] . '.php';

现在,如果有人访问 http://posnation.com/restaurant_pos pages/restaurant_pos.php 将被包含在内。

pages/restaurant_pos.php 也可以包含页眉和页脚。

<?php require( HEADER_FILE ) ?>
restaurant_pos content
<?php require( FOOTER_FILE ) ?>

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

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

In your /.index.php do something like ... (this is just a VERY simple example)

require 'pages/' . $_SERVER['REQUEST_URI'] . '.php';

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.

<?php require( HEADER_FILE ) ?>
restaurant_pos content
<?php require( FOOTER_FILE ) ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文