I'm using CodeIgniter and have just installed a LAMP stack on an Ubuntu 10.10 cloud server.
Everything is working great, and I have the Apache userdir module enabled so that my home directory sits at /home/myapp/public_html
, and I access it by going to servername/~myapp
.
Unfortuntely, .htaccess
rewrite does not seem to be working - it causes a 404 saying the file /home/myapp/public_html/index.php
could not be found - a 404 error.
Mod_rewrite is enabled.
I'm aware that you need to set the AllowOverride All
directive - I have it set in /etc/apache2/sites-enabled/default
- yet rewrite doesn't seem to be working properly.
My .htaccess
file simply contains:
RewriteEngine on
RewriteCond $1 !^(index.php|img|stylesheets|js|icons|robots\.txt|user_guide)
RewriteRule ^(.*)$ index.php/$1 [L]
And my /etc/apache2/sites-available/default
looks like:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
And finally, /etc/apache2/mods-enabled/userdir.conf
looks like:
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
</IfModule>
I've been googling and fiddling for hours, can anyone help please?
htaccess needs to be enabled with AllowOverride. This is the first thing that should be verified. If the AllowOverride directive is set to None then this will disable all . htaccess files.
Save the file and type the URL yoursite.com/foobar/ . If the reditect works and the URL gets redireted to the homepage of example.com then it's clear that your htaccess is working and being read by your Apache server. If it still doesn't work then the problem might be that your hosting provider has not enabled it.
For what it's worth, I had a very similar problem with Ubuntu Server 11.10 and LAMP. I had to run the command
sudo a2enmod rewrite
which did the trick for me. Maybe it's the solution for you or some other people coming in here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With