Page name and nicknaming it?

Hey guys,

I want to be able to use URLs like this on my site:

but I don’t want to create a directory for each one and make an index.php page for each one. Is there a cleaner / different way to do this?

Like I don’t think they have a signup directory with an index.php page in it, because I tried to access that and it said NOT FOUND.

It’s usually accomplished using ModRewrite rules in a .htaccess file.
It’s a way of telling the server to treat a request for one URL as though it was for another (the server will execute a different script).

So for example:

RewriteEngine On
RewriteRule ^(signup|login|blog)$ index.php?page=$1

When the user requests any of those 3 URLs you gave index.php will be called and it will have $_GET[‘page’]. The value of that will be either signup, login or blog.

$1 refers to the value captured in the parenthesis of the rewrite rule.


RewriteEngine On
RewriteRule ^(signup|login|blog)$ $1.php

Will request signup.php, login.php or blog.php depending on the request URL

You can search for search engine friendly URLs and ModRewrite for more info.

This is great, thank you :slight_smile:

If you are on Apache 2.2.16 or later you can skip the heavy mod_rewrite and use:
mod_dir - Apache HTTP Server FallbackResource

It is frequently desirable to have a single file or resource handle all requests to a particular directory, except those requests that correspond to an existing file or script. This is often referred to as a ‘front controller.’

 In earlier versions of httpd, this effect typically required     mod_rewrite, and the use of the -f and     -d tests for file and directory existence. This now     requires only one line of configuration.

          `FallbackResource /index.php     `

That’s good to know, still on 2.2.14 locally, but I’ll look into that when I upgrade.