1

Hello here is what I am trying to do : if someone goes to site.com/myusername they get sent to site.com/index.php?a=profile&u=myusername

should be pretty simple if you know htaccess rewrite engine. also any good beginner tutorials for something similar ?

here is my present .htaccess:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{request_filename} -f [OR]
RewriteCond %{request_filename} -d
RewriteRule ^ - [L]

RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ /index.php?a=$1&q=$3 [L,QSA]

RewriteRule ^(.+?)/?$ /index.php?a=profile&u=$1 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
cppit
  • 4,478
  • 11
  • 43
  • 68
  • http://stackoverflow.com/questions/3086325/using-mod-rewrite-to-hide-php-from-the-end-of-urls – Notepad Jul 16 '13 at 07:34
  • 1
    http://stackoverflow.com/questions/16388959/url-rewriting-with-php you should try searching for existing posts.. – insanebits Jul 16 '13 at 07:37
  • Loads of other posts here and elsewhere about how to rewrite urls. Try learning to use search tools and you will find development so much easier – Anigel Jul 16 '13 at 07:38
  • thank you guys im checking those links – cppit Jul 16 '13 at 08:13

3 Answers3

2

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /index.php?a=profile&u=$1 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • hello anubhava. there is already a : RewriteCond %{request_filename} -f RewriteRule ^(.*) $1 [L] RewriteRule ^(([^/]*)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L] at the top that is being used. can you edit the code please? because when i added yours underneath it didnt work – cppit Jul 16 '13 at 08:13
  • Looks like you got it working. If you're still facing issues, pls provide your current .htaccess in your question (not in comments). – anubhava Jul 16 '13 at 08:32
  • check please. I added it – cppit Jul 16 '13 at 08:40
  • 1
    I edited your .htaccess in your question with my suggested changes. – anubhava Jul 16 '13 at 09:26
1

If the url is as specified , you can do something like

if (!isset($_REQUEST['u'])) {

$x = $_SERVER['REQUEST_URI'];
$y = str_replace('?', '', $x);
$z = str_replace('/', '', $y);
header("Location: ?a=profile&u=$z"); }

Not really a good solution though, but this was what I could think of..if you want to do it in php..

Niket Malik
  • 1,075
  • 1
  • 14
  • 23
0

I know you already got the answer. But i just figured it before one hour. But my system problem so only i am posting it later. This is also one way to do.

Options +FollowSymlinks
RewriteEngine On
RewriteBase /  
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ /index.php?a=profile&q=$1
Ananth
  • 1,520
  • 3
  • 15
  • 28