Rewriting URL from htaccess is doing wrong - php

I have a Laravel project and I have defined routes like:
Route::get('/', 'WebController#index');
Route::get('/user/signin', 'WebUserController#userLogin');
Route::get('/user/signup', 'WebUserController#userRegister');
Route::post('/user/save', 'WebUserController#userSave');
And the absolute routes of my project are:
localhost/project/ (it's working ok)
localhost/project/user/signin wasn't working ok.
Then, I added a .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>
And the routes for signin and signup are working good, except when I'm trying to use user/save from signin is redirecting to:
localhot/user/save
What is wrong with my .htaccess fie?

Related

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.

How to remove public/index.php from url in laravel 5?

I am using laravel 5 and having one problem when i upload my project on rackspace it is showing public/index.php in the url. Without this my project is not working.
Please help me .
Htacesss of my public is 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>
With regards
Harpartapsingh
You do this by making the /path/to/laravel/public folder itself your webroot in Apache/nginx instead of /path/to/laravel. With that, and the standard .htaccess in the public folder, you should be able to access your routes without the public or index.php URL segments.
copy your .htaccess file from your public folder and paste in your root directory
with this code inside .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]

why show NotFoundHttpException

I have install a fresh copy of laravel 4.2
When i visite home route (localhost/public/) it work fine but when i visit other route as like "localhost/public/kk" it show NotFoundHttpException.
here is my route.php file
<?php
Route::get('/',function(){
return View::make('hello');
});
Route::get('/kk',function(){
return View::make('hello');
});
here is .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]
The entry point for all requests to a Laravel application is the public/index.php, therefore it would be available here --> localhost/public/index.php/kk
for further info you can go to this link.
First check if you have enabled the mod_rewrite module.
Then.. according to the documentation you should try an alternative .htaccess if the .htaccess that ships with Laravel does not work.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Edit: Enable mod_rewrite in xampp

Laravel 5 - URL Rewriting and CSS conflict

I have a problem in Laravel 5 between my .htaccess for the URL rewriting and my CSS files. First of all, here is my project tree:
I have a .htaccess in my public folder as you can see on the picture. Here is the content of my .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -Indexes
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^ index.php [L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
</IfModule>
This is the code I use to remove "index.php" in URLs. For example, http://localhost/mySite/public/index.php/about becomes http://localhost/mySite/public/about.
Now, I have a master page (in /resources/views/) and in this master page I would like to reference the css file which is located in /public/css/style.css. I added this code in my master page:
<link rel='stylesheet' href="{{ URL::asset('css/style.css') }}" >
This does not work with the current htaccess but if I comment the line RewriteRule ^ index.php [L] in my htaccess and access to the URL (with "index.php") the stylesheet is well referenced. I think I have to add an other line in htaccess but I have no idea what I have to add.
I hope you can help me and don't hesitate to ask for more details. Thanks.
Why did you change the default .htaccess?
It should be like 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>
The two RewriteCond prevent requests for files to be routed to Laravel. But they have to be before the RewriteRule to be effective.

Laravel: Setup .htaccess of Folder outside of Laravel App

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

Categories