Welcome Guest, Not a member yet? Register   Sign In
twitter link url for user page
#1

[eluser]GregSmith104[/eluser]
How would I go about handling http://mysite.com/<username> so that it calls a "user" controller, but hides the "user" controller in the url?

I don't want something like this http://mysite.com/user/<username>

Would this be best achieved using URL ReWriting in the .htaccess file or is there some way through the Codeigniter URI classes that I can lookup the <username> and if it's valid route to the "user" controller passing the <username>.


Thanks
Greg
#2

[eluser]GregSmith104[/eluser]
Got it Wink

I used the route.php config file and added the following:

Code:
$route['auth(.+)*'] = "auth$1";
$route['products(.+)*'] = "products$1";
$route[':any'] = 'user';

This is a little dirty in that I'd have to add a line for every controller other than the "user" controller, but it does work.


Greg
#3

[eluser]GregSmith104[/eluser]
Ok,

So my solution kind of works...

http://example.com/username works fine, but

http://www.example.com/username doesn't the Apache logs are showing:

File does not exist: /var/www/html/mysite/username

Is this a problem with the .htaccess file, routes, or Apache?


Thanks in advance!
Greg
#4

[eluser]Ben Edmunds[/eluser]
Post your htaccess file
#5

[eluser]GregSmith104[/eluser]
Most of this is code I got from around the net...not 100% what all of this is doing...

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
#6

[eluser]Ben Edmunds[/eluser]
I'm not sure whats up with the issue with the www... Maybe someone else can help?

in the mean time you could just rewrite it with something like this:

Code:
#RewriteCond %{HTTP_HOST} !^www\.example\.com$

#RewriteRule (.*) http://example.com/$1 [R=301,L]




Theme © iAndrew 2016 - Forum software by © MyBB