Welcome Guest, Not a member yet? Register   Sign In
.htaccess index.php rewrite not working on user directory
#1

Hello All, I need some help with this:

I'm using codeigniter 2.x and I have a .htaccess for rewrite the index.php, it works great if I put my projects on /var/www or if I make a virtual host for it.

But I want to use my user directory such as http://localhost/~userdir/myproject. If I use my user directory when I'm trying to do request to a controller like: http://localhost/~userdir/myproject/signup I get this error:


Quote:Not Found
The requested URL /index.php was not found on this server.

This is my current configuration:

.htaccess


Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]

application/config/config.php


PHP Code:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['encryption_key'] = 'myencryption_key';
//all remaining is the default config 

This config works great on http://localhost/ and also on production enviroments with a domain like http://example.com/ but not on my user directory http://localhost/~userdir/project/ neither on production like http://example.com/~userdir/project

Any thoughts? Thanks in advance.
Reply
#2

RewriteBase /~userdir/myproject/
Reply
#3

(02-05-2015, 02:08 PM)Narf Wrote: RewriteBase /~userdir/myproject/

Awesome, thanks!!! that works great!
I put the line that you've suggested and removed the slash before index.php on last line.

This is my new .htaccess


Code:
RewriteEngine on
RewriteBase /~userdir/myproject/
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favico​n\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Thanks for help Big Grin
Reply
#4

This line is redundant:
Code:
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favico​​n\.ico)

As these two lines cover it, and all other real files/directories. They basically say "if the request is not for a REAL file, and the request is not for a REAL directory, pass the request to index.php. Presumably everything from the above line is a real file or directory, so it's not needed at all.
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Reply
#5

(02-06-2015, 09:02 AM)CroNiX Wrote: This line is redundant:


Code:
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favico​​n\.ico)

As these two lines cover it, and all other real files/directories. They basically say "if the request is not for a REAL file, and the request is not for a REAL directory, pass the request to index.php. Presumably everything from the above line is a real file or directory, so it's not needed at all.


Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

ohh, I didn't know this, thanks for the observation.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB