467,895 Members | 1,373 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,895 developers. It's quick & easy.

"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
  • viewed: 2758
Share:
4 Replies
..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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andrew E | last post: by
1 post views Thread by Krazitchek | last post: by
7 posts views Thread by Alex Maghen | last post: by
4 posts views Thread by Shelly | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.