Routing URL && Sub domains |
[eluser]IronicNet[/eluser]
Hi! Im'm quite new at Ci, but since i saw the videos and the documentation (great work!) i fell in love immediatly!... (and i come from a .net world!) Well, i'm having the following problem... I have an application which each user can see their profile... the way to do this is the following: Quote:http://www.domain.com/username I used to do it via .htaccess, but now im trying to do it the CI way!... i have the following controller : (user.php) Code: <?php (routes.php) Code: $route['default_controller'] = "user"; if i type "www.domain.com" it shows "Index"... but if i type "www.domain.com/someusername" it throws a 404 error. but if i type "http://www.domain.com/index.php/username" it shows me "View". Any suggestions? some help? I'm sorry, i didn't find any post with this... or i tried the wrong keywords...
[eluser]Crazy88s[/eluser]
Hi, I come from a .NET world too and am learning my way around CI. I'll assume you are using Windows. You'll need to use a .htaccess file. Here's what I did. My application resides in a folder under my htdocs directory. I created a .htaccess file with the following contents: Code: <IfModule mod_rewrite.c> I then modified the httpd.conf file and removed the # from the line: LoadModule rewrite_module modules/mod_rewrite.so You'll need to restart apache after this. In the config.php file for my CI application I changed the following: Code: $config['base_url'] = "http://localhost/myCIFolder/"; That should do it.
[eluser]barbazul[/eluser]
@IronicNet: Unfortunately "the CI way" still doesn't get rid of the .htaccess file... you'll need it to make your examples to work. the router.php file is extremely helpful but what it doesn't replace the .htaccess, it only works on the url segment that comes after the index.php What Crazy88s says is totally correct, but I still feel like making it a little clearer for you since you come from a different universe (I mean .NET) So if you dont use .htaccess your urls will work with this syntax: http://www.domain.com/index.php/controller/method/parameters if you use .htaccess to replace (.*) to index.php$1 they will work with this other syntax http://www.domain.com/controller/method/parameters which will (internally) be rewritten to look like the first example. The resulting url is basically calling index.php and setting a server variable with the string that comes after index.php. This is the string that's analysed by the routing mechanism to extract the appropiate controller and method and it is on this string that any rules specified on router.php will be applied. I hope you find this helpful.
[eluser]IronicNet[/eluser]
This is my final .htaccess Code: <IfModule mod_rewrite.c> It's working perfectly (i erased the RewriteBase /CommunityRoute)... and i will refine it. But it's a great example.
[eluser]IronicNet[/eluser]
I forgot to add something initially... i want that when a user enter into Code: http://account.domain.com Code: www.domain.com/account/ -or- www.domain.com/index.php/account/ Is there anyway to accomplish this? via dns or .htaccess? or should i create another physical path to achieve this?
[eluser]gr0uch0mars[/eluser]
I'm using the htaccess rewrite rules to avoid having "index.php" in my URL and it works perfectly. Now the problem comes after having validated a form, it redirects me to "index.php/form" instead "/form". I'm new in this, and I have a lot to learn, but i would appreciate anyone telling me how to solve this, thanks.
[eluser]Michael Ekoka[/eluser]
@IronicNet You may wanna add something like this to your .htaccess Code: RewriteCond %{HTTP_HOST} ^(account|admin).domain.com$ @Sherlock_Brett We might need to see what you have in your .htaccess
[eluser]gr0uch0mars[/eluser]
This is what I have: Code: RewriteEngine on Something like what User Guide says. |
Welcome Guest, Not a member yet? Register Sign In |