I'm using Laravel 5. My site has url:
"mysite/subfolder/"
But now urls are not working. They redirect to "mysite". How to fix that?
My routes are:
Route::get('/page/{page}/', 'HomeController#index')->where('page', '[0-9]+');
Route::get('/', 'HomeController#index');
My link is proper:
"mysite/subfolder/public/page/7/"
But when I click it, it redirects me to "mysite".
How to add whole path to base url?
My .htacess file is:
<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>
I assume you are experiencing this after you moved your website to a host or something?
Look at this post on how to set this up:
https://driesvints.com/blog/laravel-4-on-a-shared-host
Related
I'm writing a web application in laravel and have it almost working.
The only thing that is stopping me right now is the Rewrite Engine from apache ruining one particular route.
Route it should be: http://example.org/publicaties
Route it's
rewritten to: http://example.org/public
publicaties == publication but in dutch.
I'm using the following rewrite code as this is mostly the default for laravel if not completely:
DirectoryIndex index.php
<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 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>
Any help would be awesome!
Thanks
Solved
Turns out laravel doesn't like similar names like 'publicaties' and 'publications' because after changing the url, the issue was gone. Thanks all!
I have setup on host my 5.4 Laravel project.Everything used to work just fine but now when i try to access any page other then homepage i get 404 not found even when i want to access phpmyadmin panel (www.mywebsite.com/phpmyadmin).Is this a .htaccess config problem or something wrong with the server or domain ?
this is my .htaccess file content :
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
You have to change the apache config to accept what is written in .htaccess file. This would help https://stackoverflow.com/questions/24784606/laravel-routes-not-working-apache-configuration-only-allows-for-public-index-ph
I just started learning Laravel from this series: https://laracasts.com/series/laravel-5-from-scratch/episodes/2
I use windows 10 with Wamp.
My site sits under: sites/highland.lar
I created the virtual host.
The route has this code:
Route::get('/', function () { return view('welcome'); });
When I go to: http::highland.lar I get the page: Index of/ instead of the Welcome.blade.php view.
I added an index.php file to the root folder to test, and this file works fine.
After installing laravel the public/htaccess looked like:
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Reading this link: enter link description here
I changed it to:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Nothing helps. What am I doing wrong?
Ok, solved the problem with this link:
enter link description here
I just found the problem on server. all is working fine in my localhost, but on live server, ONLY the home page route is working.
My directory is:
laravel-
css
js
local->
app
HTTP->
Controllers->
Homecontroller
admin->
Groupcontroller
config
...
Here is my htacess
<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]
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
And my route file is:-
Route::get('/group/detail', 'Groupcontroller#index');
Route::get('/group/add', 'Groupcontroller#create');
Route::get('/group/edit/{id}', 'Groupcontroller#edit');
http://www.example.com/home
My home controller is working.I think issue is with admin folder???
http://www.example.com/admin/group/detail
This is not working
Error is encountered :-
Class App\Http\Controllers\Admin\Groupcontroller does not exist
Please help me,Working fine at localhost but not on live.
Thanks in advance
Try and change the content of your .htacess to this
<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 Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Might be you forget to paste .htaccess file from /public folder to /public_html folder
so Just COPY And PASTE the .htaccess file from public folder to /public_html folder
then it will work as local
Path of Groupcontroller is Controllers/admin/Groupcontroller. So in your routes you need to access Groupcontroller with appropriate path.
Route::get('/group/detail', 'admin\Groupcontroller#index');
Route::get('/group/add', 'admin\Groupcontroller#create');
Route::get('/group/edit/{id}', 'admin\Groupcontroller#edit');
Also it is recommended to use CamelCase folder names. that is; change admin => Admin.
Check the namespaces compared to directory names. The cases should match.
You can try the bellow code :
After the domain name add "public" keyword between your API routes
for example:-
https://example.com/public/api/someroute
After this, you may have to update your PHP version .
i have an /admin folder and i cant delete becaus there are old files linked externaly and i need to use the /admin route.
When i use the /admin route i have a loop, if i rename the admin folder, it works, but i cant do that permanently.
If i use another route like /admin/anything, it works.
How can i have the folder and the route work together.
Here are my routes:
Route::post('admin/login/valida', ['before' => 'csrf', 'uses' => 'LoginController#getValidar']);
Route::get('admin/login', 'AdminController#Login');
Route::get('admin/asociarmenuarchivo', 'AdminController#Asociarmenuarchivo');
Route::get('admin/disenosnuevos', 'AdminController#disenosNuevos');
Route::get('admin/disenosnuevooantiguo', 'AdminController#switchDisenos');
Route::get('/admin', 'AdminController#getIndex');
The last one is the only route that doesnt work.
Here is my .htaccess:
<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
RewriteCond %{REQUEST_URI} !/cm/.*
#RewriteCond %{REQUEST_URI} !/admin/.*
RewriteCond %{REQUEST_URI} !/correo/.*
RewriteRule !^/?admin index.php [L,QSA]
RewriteRule ^ index.php [L]
ErrorDocument 401 "Unauthorised"
</IfModule>
The problem was the slash rewrite, the solution was:
RewriteCond %{REQUEST_URI} !/admin/.*
RewriteRule ^(.*)/$ /$1 [L,R=301]