如何在PHP中创建个性化的URL?

I want to convert an URL like this:

http://somesocial.com/SomeSocial/success/profile?search_user=exampleuser01

Into a personalized URL like this: http://somesocial.com/exampleuser01

I've tried creating a folder with a file inside success/preview/user_preview.php which is a copy of profile.php to get the parameter from 'search_user' with $profile_id = $_GET['profile_id'] and header('Location:'.'success/profile?'.$profile_id); To redirect the searched user for his original link.

Modified my .htaccess to:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^success/preview/user_preview?search_user=
RewriteRule ^/?([^/]+)$ success/preview/user_preview?search_user=$1 [L]

This works perfectly, but every time I try to access a file from the main dir (i.e Index.php) it redirects me to http://somesocial.com/SomeSocial/success/profile.php?search_user=Index.php

Why?

Try reordering your rule wit more restrictive conditions:

RewriteEngine on 
RewriteBase /

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

RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^([^/]+)/?$ success/preview/user_preview?search_user=$1 [L,QSA]