.htaccessurl-rewritingsocialengine

Socialengine url rewriting


I want to let users access their pages by typing the url http://www.mysite.com/username

So to redirect http://www.mysite.com/username TO http://www.mysite.com/profile/username

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On



  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]


  # Rewrite all directory-looking urls
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*) index.php?rewrite=1 [L,QSA]



  # Try to route missing files
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} public\/ [OR]
  RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
  RewriteRule . - [L]



  # If the file doesn't exist, rewrite to index
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]



   RewriteRule ^([A-Za-z_-]+)$ /profile/$1 [R] 


</IfModule>

Why wont this work?


Solution

  • Try putting your rule before the other rules. You can start this way.

    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^([A-Za-z_-]+)$ /profile/$1 [R]