Laravel: Setup .htaccess of Folder outside of Laravel App - php

I have Laravel installed in /var/www/html
I have a PHP script installed in /var/www/html/i/
The htaccess of /var/www/html/ is
<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]
The htaccess of /var/www/html/i/ is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.+)$ /?variable=$1
</IfModule>
Trouble is whenever I go to
/i/somevariable
I get a 404 error from my laravel app.

Make a .htaccess file in your root folder with this content:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([A-Za-z0-9-]+)/i/?$ index.php/i/?s=$1 [NC,L]
This should work fine.

if you are using apache
read mod_rewrite
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
dont just turn on,
use rewrite rule

Related

Laravel Project on Existing Website

I'm new to the Laravel framework. I am considering learning it and using it for a personal project, but as I am reading through the documentation I see that the web server document root would need to be set to the project folder.
Is it possible to integrate a laravel project with an existing webiste built with PHP and apache? For example, if I have a wordpresss install and wasn't using a framework but wanted tp create a subsite, I could just add more html and php files into a folder somewhere on the existing site or use a different vhost. Not sure if integrating would be so easy with Laravel,though.
Yes, it's possible. The solution I mentioned here should work for you.
To make it work you should modify both Laravel and Wordpress .htaccess files.
Laravel .htaccess example:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
#Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/blog/ # <=== NEW LINE!!!!
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Wordpress .htaccess example:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/ # <==== CHANGED LINE!!
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L] # <==== CHANGED LINE!!!
</IfModule>

Laravel on Plesk Routing Issue

I can't access my routes when I uploaded my site on Plesk. I get 404 error
I am using Laravel Version 4.2
I made the default directory to httpdocs/public/
Here's my .htaccess file in public folder.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Please help.

http://127.0.0.1/tp/index.php/movies change this url to http://127.0.0.1/tp/movies using .htaccess

I am using laravel framework for mtdb i wanna change http://127.0.0.1/tp/index.php/movies this url to
http://127.0.0.1/tp/movies means i want to add to remove index.php using .htaccess
Here is the .htaccess
I have
<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]
There are many solutions for removing the index.php such as Laravel 4 remove Index.php from URL
But i would suggest you 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.

.htaccess causes issues in sub-folders

Here is my .htaccess to rewrite public/index.php
I'm using the Laravel php framework.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /(code|tmp) [NC]
RewriteRule ^ - [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>
Here the folders 'code' and 'tmp' can be accessed like normal.
If I add a set of nested folders, and add the default Laravel htaccess to remove the public/index.php
<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>
It doesn't work inside the nested folder.
It works good if I don't have the firstly given .htaccess in the root directory. Once I given my .htaccess it is not working.
Is the .htaccess in the root directory causing effect to the sub folder ?
If so , how can I fix that
Note : This is the question where I got .htaccess previously
.htaccess exception makes issue on main directory

Apache redirect only working with index.php and not without?

I have the same instance of laravel running on two different machines. They both have the same .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>
The one system is running PHP 5.5, and the other PHP 5.4. The problem is, this works on the one system but not the other:
http://www.example.com/register
However, this works on both:
http://www.example.com/index.php/register
What possible htaccess could there be that causes it to only work with index.php? I need it to work without index.php as well?
You may need to use RewriteBase / above RewriteEngine On if there is an inconsistency between the systems in what the root url is

Categories