views:

27

answers:

2

I'm having problems implementing friendly SEO urls on my local (Mac OS X Snow Leopard) development server.

*Note: site.com is just an example

(1) Currently my site's root is set up with a virtual host pointing to a sub-directory of my Sites folder.

(2) Pages are currently being accessed in the following format: http://site.com/index.php?page=login

(3) I want to implement SEO as something like: http://site.com/login

(4) I've edited my personal apache configuration to include AllowOverride All

(5) I've created an .htaccess file called site_com.htaccess and placed it into the document root of site.com. The content of this file is:

RewriteEngine On
RewriteRule ^(.*).html /index.php?page=$1

(6) I've then restarted apache with sudo apachectl restart

What have I done wrongly?

+2  A: 

Rename the file from site_com.htaccess to simply .htaccess.

meagar
That doesn't do any thing. The browser complains about the url not being found.
Tunji Gbadamosi
@Tunji Well, for one thing your pattern expects `.html` at the end... Are you navigating to `/login` or `/login.html`?
meagar
@meagar lol, my mistake, silly me. login.html works. How would I achieve /login? Thanks.
Tunji Gbadamosi
@Tunji `RewriteRule ^(*)$ /index.php?page=$1`
meagar
+1  A: 

You're having problems applying your rewrite rules.

Use something like this:

// if not a file
RewriteCond %{SCRIPT_FILENAME} !-f
// if not a directory
RewriteCond %{SCRIPT_FILENAME} !-d
// pass all params back to index.php
// QSA stands for query string append
// L stands for last rule
RewriteRule (.*) index.php?$1 [QSA,L]

And here is the manual for future reference! ;)

Frankie
Thanks for the manual.
Tunji Gbadamosi