2

I'm looking for the right .htaccess rule to make a Facebook.com/user URL like

What I want if I access for example

www.domain.com/StackOverFlow

It will be rewrite to

www.domain.com/index.php?category=StackOverFlow

Or

www.domain.com/category.php?item=StackOverFlow

Any help? I've tried some question here, but they doesn't explicit do this behavior.

Thanks in advance

Edited:

Forgot to say that I only want to be redirected using this rule, anything that after the domain, doesn't have any extension

For example it should redirect www.domain.com/categoryDescription but no www.domain.com/categoryDescription.php or www.domain.com/categoryDescription.html

Garis M Suero
  • 7,974
  • 7
  • 45
  • 68
  • There's an interesting tutorial on this here: http://www.noupe.com/php/10-mod_rewrite-rules-you-should-know.html – peacemaker Jun 21 '12 at 20:20

3 Answers3

3

Try:

RewriteRule ^StackOverFlow$ index.php?category=StackOverFlow [NC,L]

or:

 RewriteRule ^StackOverFlow$ category.php?item=StackOverFlow [NC,L]

In generally:

RewriteRule ^([^/]*)$ index.php?category=$1 [NC,L]

or:

 RewriteRule ^([^/]*)$ category.php?item=$1 [NC,L]
Mateusz Rogulski
  • 7,357
  • 7
  • 44
  • 62
3

The example below takes the URI after .com/ and assigns that to $1. You can do the same for "item"

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?category=$1 [L]
Robert
  • 1,899
  • 1
  • 17
  • 24
  • For example it should redirect `www.domain.com/categoryDescription` but no `www.domain.com/categoryDescription.php` or `www.domain.com/categoryDescription.html` will it work? – Garis M Suero Jun 21 '12 at 20:27
3
<IfModule mod_rewrite.c>
  RewriteEngine on
  # Rewrite URLs of the form 'x' to the form 'index.php?category=x'.
  RewriteRule ^(.*)$ index.php?category=$1 [L,QSA]
</IfModule>
Bob
  • 128
  • 1
  • 6
  • For example it should redirect `www.domain.com/categoryDescription` but no `www.domain.com/categoryDescription.php` or `www.domain.com/categoryDescription.html` will it work? – Garis M Suero Jun 21 '12 at 20:26