Home Ask Login Register

Developers Planet

Your answer is one click away!

Matthew O'Connor February 2016

PHP: Custom Designed URL

Im trying to send users to custom url's based on their profile information. Instead of sending a user to www.website.com/profile/john.doe i want to send them to www.website.com/john.doe - however when i try remove the "profile" portion of the url. I get an error saying

The john.doe_controller.php file could not be found.

unless im understanding wrong, i dont want to create a new controller file for every user. is there a .htaccess rule i could use for this.

Thanx in advance.


Ravi Hirani February 2016

You should use below rule in your root .htaccess file:-

RewriteEngine On
RewriteRule ^profile/(.*)$ /$1 [L,R=301,QSA]

Hope it will help you :)

starkeen February 2016

You can use the following code in Root/.htaccess :

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /profile/$1 [NC,L,QSA]

Post Status

Asked in February 2016
Viewed 1,677 times
Voted 6
Answered 2 times


Leave an answer

Quote of the day: live life