0

I have a controller named (for example) TheLink, and I can normally access it through mywebsite/index.php/TheLink. Is it possible to make a RewriteRule in htaccess to access it via mywebsite/index.php/The-Link without it redirecting to TheLink? So basically what I want it the URL to say mywebsite/index.php/The-Link (with dash) but use the TheLink controller. I've tried

RewriteRule ^The-Link$ index.php/TheLink [L]

but that just redirects me to the default CodeIgniter 404 Page

GTCrais
  • 2,039
  • 2
  • 26
  • 32

2 Answers2

1
# To remove index.php from URL

RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Additionally if website is hosted in another directory not just root, add this:

RewriteBase /some_directory/
Waqar Alamgir
  • 9,828
  • 4
  • 30
  • 36
  • Thanks for that, but that wasn't what I asked. My question was how to use dashes in the URL since controller classes obviously can't be named with dashes. Example: desired URL: .../My-Link/ ---- Controller name: MyLink – GTCrais Nov 22 '12 at 15:34
0

Well, apparently this problem has nothing to do with htaccess and is solved in a completely different way. Solution found here:

Codeigniter Routes regex - using dashes in controller/method names

Edit: Also, a number of different solutions for this, including the one above, found here: http://ellislab.com/codeigniter/forums/viewthread/124396/

Community
  • 1
  • 1
GTCrais
  • 2,039
  • 2
  • 26
  • 32