Ubuntu 12.04 Laravel and mod rewrite - mod-rewrite

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.

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.

Run the following command in Terminal to enable mod_rewrite.
sudo a2enmod rewrite
Now restart Apache.
sudo service apache2 restart

Related

Apache2 Rewrite Rules result in 404

I'm running Ubuntu 20.04 lts with Apache 2. I enabled mod_rewrite, but when my rules are enabled it results in a 404 error.
This is my current (stripped down) .htaccess file and I still get a 404:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?page=$1
I've configured my virtualhost like so:
<VirtualHost *:80>
ServerName website
ServerAlias www.website
ServerAdmin webmaster#localhost
DocumentRoot /var/www/website
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/website/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
What have I done wrong? It works on IIS.
Nvm already solved it, somehow the MultiViews option was causing trouble or I made a type error.
replaced
Options Indexes FollowSymLinks MultiViews
with this
Options Indexes FollowSymLinks
And it works now

laravel httpd document root doesn't change

it's my first time to use laravel and config apache and I've a problem with apache document root, it doesn't change.
It always show apache homepage
I'm using a vm with virtualbox, and my conf.d file finish with this lines:
DocumentRoot "/var/www/laravel/public"
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName 192.168.56.3
#ServiceAlias www.test.laravel.com
DocumentRoot /var/www/laravel/public
</VirtualHost>
<Directory "/var/www/laravel/public">
Options FollowSymLinks
ReWriteEngine On
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</Directory>
Do you know what is wrong?
Thank you

.htaccess <VirtualHost not allowed Mac

I am trying to setup crud app using http://crud-admin-generator.com/ on my Mac
So I followed the steps on the above link to get all the entities generated.
While running the server I needed to setup the .htaccess file on my mac throws the following error when I run localhost on my mac machine.
/.htaccess: <VirtualHost not allowed here
My configurations are as follows
/etc/apache2/httpd.conf
DocumentRoot "/Users/akshat/Sites"
<Directory "/Users/akshat/Sites">
/etc/apache2/users/akshat.conf
<Directory "/Users/akshat/Sites/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And /Users/akshat/Sites/.htaccess
<VirtualHost *:80>
DocumentRoot /Users/akshat/Sites/admingenerator/web
DirectoryIndex index.php
<Directory "/Users/akshat/Sites/admingenerator/web">
Options Indexes FollowSymLinks
Order Allow,Deny
Allow from all
AllowOverride all
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value open_basedir none
</ifModule>
</Directory>
</VirtualHost>

RewriteBase with WAMP not working (vhost)

I have a problem, let me explain.
Rewrite_module is enabled on WAMP
My host is mapped:
127.0.0.1 localhost
127.0.0.1 mydomain.com
My vhost declared on WAMP:
<VirtualHost *: 80>
ServerAdmin contact#mydomain.com
DocumentRoot "E:/wamp/www/subfolder/"
ServerName mydomain.com
ErrorLog "logs/mydomain.com.log"
CustomLog "logs/mydomain.com.log" common
<Directory "E:/wamp/www/subfolder /">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all
</ Directory>
</ VirtualHost>
For now, no problem, mydomain.com arrives on E:/wamp/www/subfolder/
My projects are in sub folders such as E:/wamp/www/subfolder/my-project/
I have a htaccess with:
<Mod_rewrite.c IfModule>
RewriteEngine On
RewriteBase /my-project/
RewriteRule ^index\php$ - [L]
RewriteRule ^assets/css/(.*) /my-project/content/themes/assets/css/ $ 1 [QSA, L] [QSA, L]
RewriteCond% {REQUEST_FILENAME}! F
RewriteCond% {REQUEST_FILENAME}! -d
RewriteRule. /my-project/index.php [L]
</ IfModule>
My problem comes here. If I go on mydomain.com/my-project/ it comes to the site with no problem, but the css (for example) are not loaded, because the link is:
mydomain.com/content/themes/assets/css/
It should have:
mydomain.com/my-project/content/themes/assets/css/
I think the RewriteBase not working and I do not know why.
Thank you very much and sorry for my english.
I think you misunderstood the point of a Virtual Host.
You should create a Virtual Host for EACH of your projects so something like this
<VirtualHost *: 80>
ServerAdmin contact#mydomain.com
DocumentRoot "E:/wamp/www/subfolder/project1"
ServerName mydomain1.com
ErrorLog "logs/mydomain.com.log"
CustomLog "logs/mydomain.com.log" common
<Directory "E:/wamp/www/subfolder/project1">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *: 80>
ServerAdmin contact#mydomain.com
DocumentRoot "E:/wamp/www/subfolder/project2"
ServerName mydomain2.com
ErrorLog "logs/mydomain.com.log"
CustomLog "logs/mydomain.com.log" common
<Directory "E:/wamp/www/subfolder/project2">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
Allow from all
</Directory>
</VirtualHost>
This makes each project look and react like it was a single website on its own unique Apache instance and makes moving your projects to live servers more reliable.
You also do not need a .htaccess now unless this one project actually requires it.

remove index.php from url in laravel in ubuntu

I have tried several ways to remove index.php from my URL.
problem like
url not working(i want this): http://mysite.in/our-story
url working(i don't want this): http://mysite.in/index.php/our-story
1) I have tried to enanble rewrite_mod but it is already enabled.
2) I have tried to this code into .htaccess file but problem is not solved.
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L] </IfModule>
any file installation is remaining?? then tell me?? (but i have installed everything.)
my 000-default file is:
ServerAdmin webmaster#localhost
ServerName mydomain.in
DocumentRoot /var/www/mysite/public
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/mysite/public/>
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>
Please give me solution for that.
thanks friends!!!
Change AllowOverride to all instead of none.
by Jason Lewis
Check if .htaccess permissions are set to www-data (or corresponding Apache user)

Resources