djmzfKnm
djmzfKnm

Reputation: 27195

What is the best way to organise a project for URLs?

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.

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.

Upvotes: 0

Views: 143

Answers (4)

Pekka
Pekka

Reputation: 449605

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.

Upvotes: 1

A. M.
A. M.

Reputation: 565

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.

Upvotes: 1

Fanis Hatzidakis
Fanis Hatzidakis

Reputation: 5340

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

Upvotes: 3

Mad Scientist
Mad Scientist

Reputation: 18551

.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

Upvotes: 1

Related Questions