for some reasons i’ve been having problems with mod rewrite, i have the index.php removed from the url ok but when i try to do the same for profiles it shows some contact webmaster page.
Now i’m taking the routes option but i have a little problem.
My url is http://website.com/user/profile/user_profile/username
I have this in my routes
$route['profile/(:any)'] = 'user/profile/user_profile';
So when i type in website.com/profile/username, it works fine. My question is, what if i want to get rid of the /profile as well and have website.com/username, how do it go about it with routes?
Just incase, i might as well put my trail with modrewrite on here so all you brilliant minds can tell me where i’m going wrong.
Options FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|javascript|cron|sit-env|robots\.txt)
RewriteCond $1 !^(index\.php|javascript|sit-env|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond $1 !^(index\.php|images|css|javascript|cron|sit-env|robots\.txt)
RewriteCond $1 !^(index\.php|javascript|sit-env|robots\.txt)
RewriteRule ^([0-9a-zA-Z]+)([\/]?)$ /user/profile.php/user_profile/$1 [L]
Thanks in advance 🙂
I simply used the
404_overridemethod to capture any routes not already defined in CodeIgniter and then done a database look up before showing the 404 page.My example is actually for a CMS however it could easily be changed to suit your requirement.
Within my
application/config/routes.phpfile, I simply putreplacing
controllerwith the controller that contains theerror_404action.You could use the segments collection to find the username passed to
www.domain.com/usernamefailing that, in line with your original request:The above will route
www.domain.com/profile/abc123towww.domain.com/user/profile/user_profile/abc123Hope this helps?