组织 URL 项目的最佳方式是什么?

发布于 2024-09-19 09:29:33 字数 1568 浏览 4 评论 0原文

我正在开发一个门户网站(PHP/MYSQL),该门户网站分为 3 个部分:照片、视频、文章。每个部分都有自己的提交表单,用户可以使用该表单提交与其帐户相对应的照片、视频或文章。

因此,我认为该 URL 应该类似于

等。

与视频和文章部分相同。现在我很困惑要使用什么。

  • 我应该使用 .htaccess 来创建此类类型的 URL 吗?
  • 或者我应该使用其中包含index.php的文件夹作为/photos/或/photos/browse/,如下所示。所有文件夹都将有index.php,因此将通过文件夹名称访问它们,URL 将如下所示 http:// example.com/photos/browse/
  • 或者我应该传统地使用 photos.php 和 browser-photos.php 。但这种方法看起来不太好,也不太有条理。

我可以通过 htaccess 轻松实现这一点,但有些人说这会减慢您的网站速度,因为每次请求 URL 时它都会处理 htaccess。

我还有一个问题,像 digg、flickr 这样的网站是如何形成这种 URL 的。这些都是相当大的网站,每天有数百万的页面浏览量,所以他们不使用 htaccess 吗?

请指导我!

谢谢。

I am working on a web portal (PHP/MYSQL) which have 3 sections photos, videos, articles. Each section has its own submission form using which user will submit photos, videos or articles corresponding to their accounts.

So, that URLS which I thought should be like

etc.

Same as for videos and articles sections. Now I am confused here to what to use.

  • Should I use .htaccess to create such type of URLs?
  • Or I should use folders with index.php in it for /photos/ or /photos/browse/ like this. All folders will have index.php so they will be accessed by folder names and URL will look like this http://example.com/photos/browse/
  • Or I should go traditionally and use photos.php and browse-photos.php . But this method not looks good and organized.

I can achieve this by htaccess easily but some peoples says that it will slow down your site, because it will process htaccess every time a URL will be requested.

I have one more question, how the sites like digg, flickr does this URL formation. These are pretty big site with millions of page-views a day, so are they not using htaccess?

Please guide me!

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

病女 2024-09-26 09:29:33

为此,您可以使用 .htaccess 和 apache 的 mod_rewrite (或类似的其他 Web 服务器)。使用 mod_rewrite,您将重写传入的 url 以适合您的脚本架构。放缓幅度可以忽略不计。大多数大型网站都使用这种技巧。

因此,举一个粗略的例子,假设您有以下工作应用程序:

./index.php
./index.php?section=about
./index.php?section=contact
./index.php?section=help
./photos.php
./photos.php?section=browse
./photos.php?section=submit
./photos.php?section=edit

然后您可以将其放入 .htaccess

# Turn on URL rewriting
RewriteEngine On

# These are very verbose to show the point. Later you can make them smarter
RewriteRule about index.php?section=about
RewriteRule contact index.php?section=contact

#all under photos/* goes to photos.php
RewriteRule photos/(.*) photos.php?section=$1

然后将代码放在 index.php 和 photos.php 中的正确位置

You can use .htaccess and apache's mod_rewrite (or similar for other web servers) for this. With mod_rewrite you'll be rewriting incoming urls to fit your script schema. The slowdown is negligible. Most big sites use this kind of trick.

So for a rough example, lets say you have the following working application:

./index.php
./index.php?section=about
./index.php?section=contact
./index.php?section=help
./photos.php
./photos.php?section=browse
./photos.php?section=submit
./photos.php?section=edit

Then you can put this in .htaccess

# Turn on URL rewriting
RewriteEngine On

# These are very verbose to show the point. Later you can make them smarter
RewriteRule about index.php?section=about
RewriteRule contact index.php?section=contact

#all under photos/* goes to photos.php
RewriteRule photos/(.*) photos.php?section=$1

And then place your code in the right places in index.php and photos.php

枕梦 2024-09-26 09:29:33

我可以通过 htaccess 轻松实现这一点,但有些人说这会减慢您的网站速度,因为每次请求 URL 时它都会处理 htaccess。

对于非常非常高流量的站点来说,看到没有太多基于正则表达式的重写规则确实很重要,因为它们在某种程度上是性能密集型的。

不过,我们大多数人不需要担心。与阿帕奇一起去吧。

I can achieve this by htaccess easily but some peoples says that it will slow down your site, because it will process htaccess every time a URL will be requested.

For very, very, very high-traffic sites it is indeed important to see that there are not too many regex-based rewrite rules because they are somewhat performance intensive.

Most of us don't need to worry, though. Go with Apache.

耳钉梦 2024-09-26 09:29:33

.htaccess 很可能不会成为您的瓶颈,如果您需要真正的高性能,您将无法回避衡量问题所在。真正的大网站并不是一个很好的参考,在这种规模下,问题是非常不同的。

最灵活和最常见的方法是使用 mod_rewrite 重定向到一个页面,然后调用应用程序的适当部分。

此时我不会担心性能,而是更担心灵活性和可维护性。

您还可以将重写规则放在 apache 主配置中并节省 .htaccess 的开销,这应该会快一点

.htaccess most likely won't be your bottleneck, if you need really high performance you won't get around measuring yourself where the problems are. Really big sites are not a good reference, at that scale the problems are very different.

The most flexible and common way is to use mod_rewrite to redirect to one page that then calls the appropriate part of your application.

I would not worry about performance at this point, but more about flexibility and maintainability.

You can also put your rewrite rule in the apache main config and save the overhead of .htaccess, that should be a bit faster

℉絮湮 2024-09-26 09:29:33

与使用大量文件夹相比,使用 htaccess 将使组织文件变得更加简单。是的,它对性能有影响,但是,除非它是一个真正高流量的站点,否则影响不会很明显。如果您担心性能,请记住,糟糕的代码比任何重写规则都会更严重地减慢您的网站速度。

Using htaccess will make it much more simple to organize your files than with lots of folders. Yes, it has an impact on performance, but, unless it's going to be a really high-traffic site, the impact won't be noticeable. It you're worried about performance, keep in mind that bad code can slow down your site a lot more than any rewrite rules.

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