Why only home page route working on live server? - laravel

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

Related

Rewrite Engine Route Conflict

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!

URL redirects to public/public if using www

If I go to website.com then my website works correctly.
If I go to www.website.com then I get redirected to www.website.com/public/public which 404s.
If I then go to www.website.com/public it works correctly (but I don't want the added /public)
I want it so that both website.com and www.website.com use the same page.
without any publics added/needed in the URL.
Here is the .htaccess which is in the root laravel folder (inside public_html)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
#RewriteBase /laravel/
# 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>
AddType x-httpd-php72 .php
The reason I'm using the rewrite rules are so that I can access assets without using /public e.g /public/css/app.css is /css/app.css
I fixed it. The issue was my env had http://website.com rather than http://www.website.com.

I'm forcing SSL with htaccess but it isn't working with URLs that link to files

I realised that my site is not redirecting correctly when the URL link to a file (a pdf in this case). The others urls of my site are working perfectly. This is my htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
It's strange because after differents ways of typing my url I found this:
If I type "myweb.com/urltopdf", it is redirected to "https://myweb.com/urltopdf"
If I type "https://myweb.com/urltopdf", URL works
If I type "http://myweb.com/urltopdf", it isn't redirected and the url doesn't work. This case is my problem.
I dont know if it's important but I am using laravel 5.2.
Thanks.
EDIT: It works on firefox and edge but not on chrome.

All page show 404 apart from index

Even /home is 404. I just start learning laravel, I don't know if I did something wrong.
After reinstall composer and created a new project the problem still
exist.
Xampp is running.
Here is the .htaccess in public:
<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>
have you added Route::get(/home, HomeController#index); to your routes file?

Laravel routes are not working on live server

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 .

Resources