1

localhost/mysite/public - working localhost/mysite/public/index.php/tasks - working localhost/mysite/public/tasks - NOT WORKING ERROR 404

I tried almost everything and still have problem. I have got mod rewrite on - i used : sudo a2enmod vhost_alias rewrite and restarted the server

my .htaccess file:

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

my etc/apache2/sites-avaliable/default its like:

 <VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>

when I change AllowOverride to All - only "localhost/" is working but i cant run any sites like "localhost/mysite" .

I have tried to add to default file a next virtual host like:

 <VirtualHost *:80>
  DocumentRoot /var/www/mysite/public/
  <Directory /var/www/mysite/public/>
  AllowOverride All
 </Directory>
 </VirtualHost>

but it is not working at all.

Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
Kriss
  • 435
  • 1
  • 10
  • 22

2 Answers2

4

First, if you are using Laravel 3 make sure that you have updated /application/config/application.php and made the "application index" var to a null value, like "". https://github.com/laravel/laravel/blob/master/application/config/application.php#L42

If you've already done that, try setting up a vhost. It sounds like you are using Apache 2.

First create an additional vhosts file, for example /etc/apache2/sites-available/laravel

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName laravel.dev
    ServerAlias *.laravel.dev
    DocumentRoot /home/kriss/projects/laravel/public
</VirtualHost>

Then update your /etc/hosts file and add

127.0.0.1 laravel.dev

Then (and this may be the step you missed before)

sudo a2ensite laravel

This will make a sim link in /etc/apache2/sites-enabled to your vhost config file. Finally restart your server:

sudo service apache2 restart

You should be able to connect with the url http://laravel.dev, and your rewrites should be working.

Makita
  • 1,812
  • 12
  • 15
  • I am using laravel 4 and cant find application.php it is only config/app.php but there is no index in it – Kriss Feb 16 '13 at 10:49
  • Okay, if you're on L4 try and install under a vhost. – Makita Feb 16 '13 at 10:57
  • http://laravel.dev -- error 404 i did exactly as you said - i checked there is laravel in sites-enabled so it shoud work but unfortunately its is not.I did it in windows but in ubuntu i cant – Kriss Feb 16 '13 at 11:02
  • ok Now i have error 500 so it is connecting to site but still it is problem – Kriss Feb 16 '13 at 11:09
  • first, make sure the DocumentRoot in your virtual host config points to a directory *other* than the main /var/www/. Then try a simple empty directory with index.html to make the the laravel.dev vhost works. After that, you can start looking at the laravel config. – Makita Feb 16 '13 at 14:29
  • finally i forced it to work - have mistake in directory so now its ok thank you all for help – Kriss Feb 16 '13 at 17:56
4

Run the following command in Terminal to enable mod_rewrite.

sudo a2enmod rewrite

Now restart Apache.

sudo service apache2 restart
Ayon Khan
  • 41
  • 1