CodeIgniter Forums
[solved]Virtual links aren't working while running site on a subdirectory - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [solved]Virtual links aren't working while running site on a subdirectory (/showthread.php?tid=51689)



[solved]Virtual links aren't working while running site on a subdirectory - El Forum - 05-14-2012

[eluser]Saoshyant[/eluser]
I have been using CI for a couple of web sites running on the root without much of an issue, but this time I'm working on one that needs to run on a subdirectory, let's call it "dir".

Now, I have the homepage loading fine under http://example/dir/ but internal links like /dir/something aren't working. They give me a server 404 message, not even a CI 404 message, so I assume the problem is with .htaccess

In fact, /dir/index.php/something works.

This is what I have on the .htaccess right on /dir/:

Code:
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I have also tried to change it to RewriteBase /dir/ but that didn't work.

Checking the manual, it could also be a routes.php issue.

I currently have:
Code:
$route['search'] = 'search';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';

And I have tried to replace $route['(:any)'] with $route['dir/(:any)'] but that just made the homepage go 404, so this is probably the wrong place.

This is likely a very simple problem, but I can't for the life of me figure out what I'm doing wrong.

EDIT: Ok, the solution was simple: you have to add a specific mod_rewrite rule for /dir/ on the .htaccess under the root / and not in /dir/.