Having trouble with mod_rewrite on my Laravel app - apache

Currently, I can only access links on my Laravel project if they are in the form of domain.com/index.php/somepage. I want to be able to be able to get access with a URL like domain.com/somepage. On my local Windows machine it is working fine. My server is on Ubuntu and running Apache 2.4.6 and the rewrite module was enabled via a2enmod rewrite. My .htaccess is the default one that ships with Laravel:
<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've also tried the alternate in the Laravel docs both with and without the <IfModule>:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I realize this has been asked before but I still can seem to get it working with other examples that I've seen. I'm guessing it must be some Apache configuration that I don't have set.

Did you make sure that allowoverides all was in your httpd config?
That sounds like your issue.

Related

Laravel on Plesk-Server - Only accessible by calling /public

When setting up a fresh Laravel installation, we have to run it using domain.com/public instead of domain.com.
I googled after this problem and I saw that this could be because of mod_rewrite not being enabled. However, we are running Plesk on our server and their documentation at http://download1.parallels.com/Plesk/PP12/12.0/Doc/en-US/online/plesk-administrator-guide/index.htm?fileName=74206.htm says:
The mod_rewrite module is enabled by default in Apache that comes with Plesk for Linux. To make use of the functionality, you will need to create an .htaccess file containing the desired rewrite rules - refer to the Apache documentation for more information.
Laravel is working fine, if I move the contents of public in the main folder, and the rest in a /laravel folder (simply have to adopt the main index.php file).
However I would like to keep the original file structure.
Any tips?
Just use .htaccess to redirect from / to /public. Maybe similar to this
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
You need two .htaccess files. One inside the Laravel Project and the other one inside your domain.com
Laravel Project (/var/www/vhosts/domain.com/public/.htaccess)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
main domain (/var/www/vhosts/domain.com/.htaccess)
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

Remove htaccess action to public directories

How I can disable the rewrite rule to access directories into Laravel public directory, without affecting my Laravel project?
ex: I have (asd) directory into my public Laravel but I can't access
if I remove
RewriteRule ^ index.php [L]
line and I can access, but this affects my Laravel project.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This line is doing exactly what you're asking for (which is to apply the rule on anything except real directories):
RewriteCond %{REQUEST_FILENAME} !-d
However, you seem to have an issue with your rewriting.
Did you take a look at your access logs within your web server ?

How to remove http://IP_ASDRESS/index.php/xyz from laravel 5?

I know that question has been answered number of times, but I would like to tell you what I did but still I haven't manage to remove it.
Firstly I'm hosting my app on digital ocean with apache 2, and I double check that the mod_rewrite is activated. Also I add on my htaccess in the public folder the following
<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]
on the index.php I have the following lines
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/start.php';
$app->run();
After doing this configurations I couldn't remove the index.php/xyz.
I would like to ask if I'm doing something wrong or if I'm missing something.
Ps. the http://IP_ADDRESS is working fine with the home page.
PSS. I restart the apache 2 serval times.

Object not found! in xampp

I'm using creo's module system and laravel 4. mod_rewrite is enabled and I have a .htaccess I'm also using XAMPP. The weird thing is, if I use MAMP then it works fine but if I use XAMPP that is when I get the Object Not Found error. I would like to use XAMPP because it is much more easier to create a virtual host with it then it is with MAMP.
In my url I have
http://localhost/test-modules/index.php/admin/content
but I need it to be
http://localhost/test-modules/admin/content
here is my .htaccess
Order allow,deny
Allow from all
<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]
# Disallow access to following directories
#RewriteRule ^vendor($|/|/.*|./*) – [L,R=404]
#RewriteRule ^app($|/|/*|/.*) – [L,R=404]
</IfModule>
Do yourself a favor and don't use either MAMP or XAMP. Use homestead.
http://laravel.com/docs/4.2/homestead
To give you some guides:
https://laracasts.com/lessons/say-hello-to-laravel-homestead-two

Silex rewrite, one.com

I am using this apache rewrite, when i am on my local machine.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
But after i uploaded it, to my host i get server error. They told me they dont support Options, but i can't get it working without that.
I am trying to route my Silex installation, so its /web/stats/ instead of web/index.php/stats.
I found this example for Codeigniter http://www.chrishjorth.com/blog/one-com-codeigniter-htaccess-rewrite-rules/
Anyone know how to make it work with Silex?
Same problem at some hosters. If your server has installed Apache >= 2.2.16 you can use the FallbackResource command:
FallbackResource /index.php
in your .htaccess instead of
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /skoleskak/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
See also Apache’s fallbackresource: your new .htaccess command for more information.