I have a laravel application having .htaccess file as below
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I am expecting a "Authorization" key in my request headers but its not getting through in my dev server which is running Ubuntu 14.0.4.
Same OS is in my local machine and in local machine it is working perfect.
The only difference between these two environment is in my local machine i have made a VirtualHost where as i cannot make VirtualHost on dev server so i am accessing it via IP Address / projectroot
So Finally i found the reason. It was actually my Apache default configuration file was not allowing my project .htaccess file to overwrite its configurations. That is why the line in .htaccess
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
has no effect. To allow so I put that this directive in my apache configuration file in my case its /etc/apache2/sites-available/000-default.conf
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
# AllowOverride None (Old value)
AllowOverride All #(New Value)
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>
Related
I want to deploy my laravel project on an Ubuntu server but it only shows the welcome page. I tried to login and it keeps telling me that the URL is not found on the server. I already modified my conf file in apache:
Alias /hris/imiforms /var/www/apps/hris/imiforms/public
<Directory /var/www/apps/hris/imiforms>
Option Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
and I my .htaccess file is shown below.
It has rewrite Engine all and I already executed apache restart command. Can you help me and telling me what is wrong?
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION]
{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A
RewriteCond %{REQUEST_FILENAME} !—d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ $1 [L,R=30l]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I see in your apache configuration an alias, but you don't use it.
You need to set your full directory like that, or use the alias defined before instead of full path:
<Directory /var/www/apps/hris/imiforms/public>
...
</Directory>
The /public part is very important because it is the Laravel entry point.
i am very begainer to server technologies.i know this question asked too many times but i really don't get it run.
it runs with domain.com/2.0/index.php/testbut when you remove index.php it throws
The requested URL /2.0/test was not found on this server.
Apache/2.2.15 (CentOS) Server at domain.com port 443
my project stucture
-
Public_html
--2.0(this is my project folder where ci can be located.it has sys,app,.htaccess)
--.htaccess
My domain
https://domain.com/2.0/
about the problem
i have two htaccess one at root mention above one is inside 2.0 folder
and the strange thing is what ever i write in the htaccess file it never effect anything
public_html/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
public_html/2.0/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
my httpd.conf
<VirtualHost *:443>
ServerAdmin info#domain.com
DocumentRoot /home/natural/public_html
ServerName api01.domain.net
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/access_log common
SSLEngine on
SSLCertificateFile /home/natural/api01.domain.net.crt
SSLCertificateKeyFile /home/natural/api01.domoin.key
<Directory />
Options Indexes FollowSymLinks
Allow from all
AllowOverride None
</Directory>
</VirtualHost>
i search alot and follow all the answers by Stack overflow but no luck.
The directive "AllowOverride None" in httpd.conf will disable parsing of the .htaccess file within the directories specified (in this case /) -- Can you confirm that either of your .htaccess files are in fact being parsed?
If not, does modifying the Directory subsection within your httpd.conf file to:
<Directory />
Options Indexes FollowSymLinks
Allow from all
AllowOverride All
</Directory>
Solve the issue?
For more information: http://httpd.apache.org/docs/2.4/mod/core.html#allowoverride
I assume 2.0 is the new version of the site. It looks like /2.0/.htaccess is written as though it expects to be in the root folder. Try adding RewriteBase /2.0/ after engine on. You can remove it later when you replace the contents of the root folder with that of 2.0's.
The main problem is your # Handle Front Controller... rule. It'll capture any virtual URLs before they ever get to the 2.0 folder. Try changing it to this:
RewriteRule ^(?!2\.0(?:/|$)) index.php [L]
That will exclude the 2.0 folder from the current site's virtual URLs.
You do still need AllowOverride all as recommended by the other answer, and the directory should be the same as your DocumentRoot, not /.
Add this code inside root->.htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteRule ^(?!2\.0(?:/|$)) index.php [L]
When I load pages that are not root, the page won't load without index.php before the route. The error I get:
Not Found
The requested URL /login was not found on this server.
Apache/2.4.7 (Ubuntu) Server at mydomain.com Port 80
To start with I have a virtual host file containing:
//also tried adding DirectoryIndex here before <directory>
<directory /var/www/mydomain.com>
DirectoryIndex index.php
AllowOverride ALL
</directory>
and a .htacces in my public with :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have another domain with the same .htaccess and appache config on the same server and it works fine. Also I did restart apache. If I use phpinfo on my index.php/route page I see at Loaded Modules:
mod_rewrite mod_setenvif
When running the website localy with xampp everything works fine.
For hours i'm trying now but I can't fix it or find any error (logs are empty) or any solutions that I haven't tried yet.
Edit:
Im using Ubuntu Ubuntu 14.04 x64 on a digital ocean VPS. And I tried turning it on and off again (as suggested). PHP Version 5.5.9-1ubuntu4.9. I followed this tutorial to config everything (except the direcoty part). I changed the location of the apache log and a file error.log is created on the given directory but no errors are in it.
My currently appache config is : (i've triple checked the white parts where the domain name is).
When I run apache2ctl -t D DUMP_VHOSTS I get
this looks fine to me, also tried disabling the default config but it didnt help.
Note: i've replaced my real domain with mydomain.com in reality I use my real domain on these spots.
Thought how do I know for sure that the conf file im editing is the one being used by the domain?
This is the correct Alternative htaccess rule for Laravel 5 suggested to use when the default doesn't work:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
The Options +FollowSymLinks I believe plays an important role because the DirectotyIndex acts like a symlink.
Also check /app/config/app.php to make sure you haven't set the Config('app.url') to contain the index.php.
If you have laravel installed in a sub-directory see this:
How can I remove "public/index.php" in the url generated laravel?
Have you tried turning it all off (shutdown), and then turning it on again?
If everything is as you say, it should work. I would try a restart to see if it changes anything.
If it doesn't, please update with what OS you are using.
I ended up deleting the complete conf file and copied it again from the one thats working. I took the default .htaccess from laravel and it worked. Unfortunately I still dont know what was wrong though. The current conf file looks like
<Directory /var/www/mydomain.com>
AllowOverride ALL
DirectoryIndex index.php
</Directory>
My .htaccess in /public
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I had almost exactly the same problem today, which #dasper also helped me out on. I am using digital ocean Ubuntu 14.04 also, and I had to run the command a2enmod rewrite then reload apache2. It seemed that even though rewrite appeared to be on, it actually wasn't.
First, make sure mode_rewrite is enabled. I am sure you have probably done this but I want to make sure nothing is missed.
Next, see what version of apache you are running since the syntax has changed between 2.2 and 2.4. This should not be a big deal and highly doubt this is the culprit but could save you trouble in the future
Next, try putting the rewrite condition inside of the vhost information instead of the htaccess file. This can help a little with performance as well as give you a console warn/err when restarting apache where the htaccess errors could be squelched.
<directory /var/www/mydomain.com>
Options -MultiViews
AllowOverride ALL
RewriteEngine On
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</directory>
Beyond this point I would be at a loss without some more logging or information from the server. You can also add CustomLog into the vhost and report all requests processed by the server.
The problem could be with your virtual host configuration and/or a misplaced .htaccess file.
Make sure your .htaccess file is in the public/ folder and that the DocumentRoot is set to that public/ folder.
And also, the < Directory> directive isn't controlling your virtual host but rather controls the folder itself and how it can be (or can't be) accessed on the server. To change the configuration of the virtual host do so inside the < VirtualHost> directive.
Here is an example of a virtual host configuration:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/var/www/mydomain.com/public"
DirectoryIndex index.php
</VirtualHost>
Here is the default Laravel Apache config:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and here is an alternative:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Try to rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder.
Solution found here
I believe your directory path is wrong. You need /public on the end because Laravel treats that directory as the web root. Try this:
<directory /var/www/mydomain.com/public>
DirectoryIndex index.php
AllowOverride ALL
</directory>
But the better solution is to put the contents of the .htaccess file in your virtual host. Like this:
<VirtualHost *:80>
DocumentRoot "/var/www/mydomain.com/public"
ServerName mydomain.com
ServerAlias *.mydomain.com
<Directory "/var/www/mydomain.com/public">
# Ignore the .htaccess file in this directory
AllowOverride None
# Make pretty URLs
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
Also, you should make sure your config file is loaded by running:
apache2ctl -t -D DUMP_VHOSTS
This will print a list of all the loaded vhosts. If yours isn't in that list then make sure it is enabled by running:
a2ensite [name_of_your_config_file]
Then restart apache with:
service apache2 reload
One more note: don't forget to edit /etc/hosts and add 127.0.0.2 yourdomain.com
I have installed laravel in my cpanel and localhost, but i found two way to execute/run laravel.
access the
/public/
use
php artisan serve
if i run in my notebook/localhost i can use php artisan serve and it done well like routing and database, but in my cpanel i cant use the second way, so i must use first way, but it not done well like routing and etc.
So which one is better and how to make the first way run well?
Normally, you would use
php artisan serve
on your development environment only.
On production servers, you will add a <VirtualHost> or an Alias drective in your Apache configuration.
<VirtualHost *:80>
ServerAdmin admin#localhost
DocumentRoot /path/to/your/laravel/public
ServerName your.domain.com
<Directory /path/to/your/laravel/public>
AllowOverride None
Order allow,deny
Allow from All
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</Directory>
</VirtualHost>
With this type of configuration, you can access your Laravel site as:
http://your.domain.com/
When using an Alias, your Apache configuration will be something like this:
Alias /any/path/you/want /path/to/your/laravel/public
<Directory "/path/to/your/laravel/public">
Order allow,deny
Allow from All
Options +FollowSymLinks
RewriteEngine On
RewriteBase /any/path/you/want
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</Directory>
With this configuration, you will access your laravel as: http://your.domain.com/any/path/you/want
On some web hosting providers, you don't have access to the Apache configuration,
in which case, you will have to put your configuration in an .htaccess file inside your public directory.
Laravel has a default .htaccess file inside the public directory that contains this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
You will have to check if your hosting allows .htaccess
I'm trying to create an app with laravel 4 but i'm facing a url issue. i have wamp installed on my machine. i set up a new virtual host in my httpd-vhost.conf with this code
<VirtualHost mobile.dev>
DocumentRoot "C:\wamp\www\mobile.dev\public"
ServerName mobile.dev
<Directory "C:\wamp\www\mobile.dev">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
mobile.dev is a folder and also the domain name in my localhost.
here is my Route.php file
Route::get('/','HomeController#showWelcome');
Route::post('login','LoginController#userLogin');
Route::get('login','LoginController#getUsers');
when i ask for mobile.dev/login it gives me the requested url was not found.
can you help me please solve this issue. but when i ask for mobile.dev/ its working.
Here is my .htaccess file :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Here is more details. when i remove my htaccess content everything works fine with the default url http://mobile.dev/index.php/login
So the problem is in my htaccess and the rewriting in my virtual host
It might be not Laravel problem, but seems your wamp server haven't enabled mod_rewrite in httpd.conf file yet. Locate the line -
#LoadModule rewrite_module modules/mod_rewrite.so
and remove the comment symbol '#'. Then save the file and restart Apache.
Solution:
1- when you have wamp installed in your machine please go to C:\wamp\bin\apache\Apache*.*.*\conf\httpd.conf and make sure that rewrite_mod is enabled by deleting the hash tag. (instead of using the interface provided by wamp)
2-there are two ways to enable rewriting for laravel in .htaccess file :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
or using this :
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
3- if you're setting a virtual host be sure to add this option in the <virtualhost> tag
<Directory "C:\wamp\www\mobile.dev\public">
Options FollowSymLinks Indexes Multiviews
AllowOverride All
</Directory>
Thanks a lot for your time.
Have you tried
Route::post('login','LoginController#userLogin');
without the () after userLogin?
Your <Directory "C:\wamp\www\mobile.dev"> in config should be <Directory "C:\wamp\www\mobile.dev\public"> to specify the public directory to the root of the htaccess rewrite rules.
I originally thought you were missing the </IfModule> at the end of your .htaccess file but when I posted my .htaccess file it hid the </IfModule> as well so that is a stack overflow issue. Otherwise your htaccess is correct.