Yet another mod_rewrite question

#1
[eluser]Cord[/eluser]
Hi,

I've have been browsing these forums and the CI wiki for more than 3 hours now and I thought that it was high time that I asked the gurus for help rather than wasting any more of my evening. I am relatively new to CI (but not to programming) and even more of a newbie when it comes to using mod_rewrite.

After following the various examples found here, I have successfully changed the way that a visitor to my website accesses it, by changing the address from http://www.mysite.com/index.php/controller to http://www.mysite.com/controller.

I have also set:
Code:
$route['default_controller'] = 'controller';
so that http://www.mysite.com/ works as expected.

Given that my website only has one controller I would like to set things up such that the controller's name doesn't appear in the URL at all. So in other words, I would like http://www.mysite.com/controller/action to simply become http://www.mysite.com/action. And, of course, anywhere that my website references 'controller' (including URLs and URIs that are created with the CI helpers) should also be changed appropriately. I've tried fiddling with the .htaccess file and also with the routes but nothing seems to work as expected.

Can anyone point me in the right direction with some examples?

My .htaccess file looks like this:

Code:
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /mysite/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  ErrorDocument 404 /index.php
</IfModule>

Even though my controller has several actions that I will continue to use (http://www.mysite.com/add seems far prettier than http://www.mysite.com/blog/add), I'm sure that hiding the controller from the URL must be possible - I just don't have a clue where to start.

Thanks!

#2
[eluser]Adamcbrz[/eluser]
Ok I think i have a solution for you. What worked for me is:

Code:
RewriteRule ^(.*)$ index.php/controller/$1 [L]

Let me know if that works for you.

-Adam

#3
[eluser]Unknown[/eluser]
Hello,

We're writing a web app, which also contains some normal HTML website pages (about us, contact us, etc). We've put all these pages in a controller called "site" (because we want them out of the way from the web app). However, this results is URLs such as oursite.com/site/about_us. We would rather just have the URL be /about_us ... how can we achieve this?

I posted here because it seems to be a similar issue. Unlike the earlier post, we do have other controllers.

Thanks!
Forbes


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.