473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

"Pseudo directory" urls

Hey.

I've got a very basic newbie question, I hope you can understand me.
Sorry for asking it, first of all.

I see a lot of sites (e.g. communities) with a url-structure like
this: example.com/users/paul (displaying the user profile of "paul")
or example.com/pictures/landscapes/13 (displaying pictures from the
category "landscapes", page 13). These are just examples, I hope I
didn't confuse you.

Well, in my sites I call sites with GET parameters. For example:
myexample.com/index.php?site=users&user=paul or myexample.com/
index.php?site=pictures&cat=landscapes&page=13. In my index.php file I
check for those parameters and include the relevant php file.

For me, my method somehow looks unprofessional compared to those
"pseudo urls" described at the beginning. I'm calling them pseudo urls/
directories, because I don't think there is a physical directory for
every user, for example. If a website has over 10.000 users, I don't
think they have a directory for every single user, so I guess there's
another way to get those nice-looking structure.

How to do that?

Thanks in advance.
Feb 4 '08 #1
4 3246
..oO(k3pp0)
>I've got a very basic newbie question, I hope you can understand me.
Sorry for asking it, first of all.

I see a lot of sites (e.g. communities) with a url-structure like
this: example.com/users/paul (displaying the user profile of "paul")
or example.com/pictures/landscapes/13 (displaying pictures from the
category "landscapes", page 13). These are just examples, I hope I
didn't confuse you.

Well, in my sites I call sites with GET parameters. For example:
myexample.com/index.php?site=users&user=paul or myexample.com/
index.php?site=pictures&cat=landscapes&page=13. In my index.php file I
check for those parameters and include the relevant php file.

For me, my method somehow looks unprofessional compared to those
"pseudo urls" described at the beginning. I'm calling them pseudo urls/
directories, because I don't think there is a physical directory for
every user, for example. If a website has over 10.000 users, I don't
think they have a directory for every single user, so I guess there's
another way to get those nice-looking structure.

How to do that?
The most common way to do that is called URL rewriting. On Apache
servers this can be done with the mod_rewrite module.

Apache Module mod_rewrite
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

URL Rewriting Guide
http://httpd.apache.org/docs/2.2/misc/rewriteguide.html

Another way would be to redirect all requests to the index.php and let
the script parse the request URL. This is what I do in my own framework,
because it makes it a lot easier for me to add new functions or modules
to a website without having to modify any rewrite rule in the .htaccess.

Micha
Feb 4 '08 #2
Another way would be to redirect all requests to the index.php and let
the script parse the request URL. This is what I do in my own framework,
because it makes it a lot easier for me to add new functions or modules
to a website without having to modify any rewrite rule in the .htaccess.

Micha
Thanks!
How do you do that ("redirect all requests to the index.php and let
the script parse the request URL")?
Feb 4 '08 #3
..oO(k3pp0)
>Another way would be to redirect all requests to the index.php and let
the script parse the request URL. This is what I do in my own framework,
because it makes it a lot easier for me to add new functions or modules
to a website without having to modify any rewrite rule in the .htaccess.

Thanks!
How do you do that ("redirect all requests to the index.php and let
the script parse the request URL")?
I also do it with mod_rewrite with some additional rules:

RewriteEngine On
RewriteBase /

# remove leading www. from hostname
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule (.*) http://%1/$1 [R=301,L]

# exclude static URIs from rewriting
RewriteRule ^(css|download|images|scripts)(/|$) - [L]

# redirect internally to application script
RewriteRule .* index.php [QSA]

The last rule will internally redirect all requests to my front
controller. Internally means that this only happens inside the web
server, it won't send a redirect back to the browser, so the browser's
address bar won't be affected.

The script then just takes a look at $_SERVER['REQUEST_URI']. If the
requested URI starts with "/user" for example, it would call a method to
handle such a user request, "/admin" would trigger another method for
handling an administration request and so on. It's more flexible than a
pure mod_rewrite solution, but also more complicated, though.

Micha
Feb 4 '08 #4
On Feb 4, 5:17 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(k3pp0)
Another way would be to redirect all requests to the index.php and let
the script parse the request URL. This is what I do in my own framework,
because it makes it a lot easier for me to add new functions or modules
to a website without having to modify any rewrite rule in the .htaccess.
Thanks!
How do you do that ("redirect all requests to the index.php and let
the script parse the request URL")?

I also do it with mod_rewrite with some additional rules:

RewriteEngine On
RewriteBase /

# remove leading www. from hostname
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule (.*) http://%1/$1 [R=301,L]

# exclude static URIs from rewriting
RewriteRule ^(css|download|images|scripts)(/|$) - [L]

# redirect internally to application script
RewriteRule .* index.php [QSA]

The last rule will internally redirect all requests to my front
controller. Internally means that this only happens inside the web
server, it won't send a redirect back to the browser, so the browser's
address bar won't be affected.

The script then just takes a look at $_SERVER['REQUEST_URI']. If the
requested URI starts with "/user" for example, it would call a method to
handle such a user request, "/admin" would trigger another method for
handling an administration request and so on. It's more flexible than a
pure mod_rewrite solution, but also more complicated, though.

Micha
I was stuck on the same problem, but now that I've written a .htaccess
file with your example everything works fine, thanks :-)
Feb 4 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andrew E | last post by:
Hi all I've written a python program that adds orders into our order routing simulation system. It works well, and has a syntax along these lines: ./neworder --instrument NOKIA --size 23...
4
by: Ed | last post by:
Hello All, I posted earlier about a problem I was having with editing or pasting/deleting files in the "Home Directory" of my web server. I just noticed that the "Home Directory" option in the...
1
by: Krazitchek | last post by:
Hi, i check all directories on a disk but an error occurs when i try to enter in the "System Volume Information" directory. Is there a way to "jump" this directory without to check the name of...
7
by: Alex Maghen | last post by:
Hi. I had previously installed VS2005 beta 1. I carefully followed all the steps (I thought) to deinstall it and then installed beta 2. According to the documentation, the "Data" directory which...
1
by: Dave | last post by:
I am getting te following error in a ASP.Net app that is running on Win XP Pro (SP2): Server cannot access application directory 'C:\Documents and Settings\dave\My Documents\My Visual Studio...
8
by: lawrence k | last post by:
I've installed Apache 1.3.36 on my Redhat EL 3 machine. Now I'm trying to install PHP 5.1.4. I can not get the ./configure command to work. I keep getting this error: configure: error: Invalid...
3
by: jonnyblazed | last post by:
I've searched everywhere for this but I'm not sure exactly what to search for. What I am trying to do is pass a variable to a php script via the URL. However, I don't want to use the standard...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
4
by: Shelly | last post by:
I am coding a psudo-cron job into an application that I am writing. I don't have access to write a real cron job. Here is what I did: 1 - I downloaded pseudocron.php from its website...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.