views:

309

answers:

2

I currently have a website that I am trying to optimize in terms of SEO.

I've got the site working with URLs such as:

domain.com/?app=about

In my app, $_GET[app] is set to 'about', as expected.

Now, I want to make it so that a URL like domain.com/about is treated as if it were domain.com/?app=about.

How can I do this in an Apache .htaccess file?

+5  A: 

These are known as RewriteRules, and they are fairly straightforward:

RewriteEngine on
RewriteRule ^about$ /index.php?app=about

Here's the documentation

As far as making it more generic, how about this:

RewriteEngine on
RewriteRule ^([A-Za-z]+)$ /index.php?app=$1

This will make any request to something like /staff or /contact redirect to index.php?app=[staff|contact]

Paolo Bergantino
is there anyway to make this more generic, i.e, have a general one for all apps instead of writing one for each app?
Shamil
+1 - however that example will work, but if you've got a few things to rewrite, you're better off using a more generic solution. What about `^[^/]$ index.php?app=$1` I might be incorrect in that regex but the general idea is there :P
alex
thanks to you both :D
Shamil
+1  A: 

Use this in your .htaccess

RewriteEngine on
RewriteBase /your-site # only if neccessary

RewriteRule ^([^/])$ index.php?app=$1 [R,L]

EDIT

I added the L flag meaning process this as the last rule, and the R flag which by itself does not change the URL .. just rewrites internally. Doing R=301 will forward the browser to the rewritten page, which is useful for debugging.

alex
it's getting there, but seems that something is wrong. http://thinkteen.co.uk try /contact or /staff :)
Shamil
nope :/ I still can't get my head around it
Shamil