Laravel route not working with file extension - php

I am trying to create a route in Laravel 5.1 that will work for a generic permalink.
Route::get('{generic_url}.html', 'Frontend\CMSController#generic');
When I go to a URL say /this-is-my-page.html I get a 404 page that does not originate from within Laravel (my custom 404 page does not appear). However, when I go to /index.php/this-is-my-page.html everything works fine.
I believe that this problem is originating from the configuration of the server. My .htaccess is as follows:
<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>
As I am still developing this solution, I am using the php -S localhost:8000 command to launch the web server. Could that be the cause of my problem? Is there something wrong with the default configuration? Should I move my development to a "real" server?

Related

Laravel Lighthouse-PHP GraphQL (Server cannot be reached)

I'm using Laravel - Lighthouse-PHP GraphQL server, and when I deploy it to production, I have to write public in the URL in order to work:
https://example.com/graphql (Server cannot be reached) ✗
https://example.com/public/graphql (Server connected) ✓
My .htaccess contains the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
while inside the public folder, there's another .htaccess file, contains the below:
<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>
I tried editing(or removing) this file, but the whole website stopped working.
Any idea what I'm doing wrong?
In your webserver configuration make sure the root directory (the directory that is serving requests) is set tot the public folder instead of the root directory of your app as you have now.
You should only make the public folder publicly accessible, not doing so could result in an attacker to access or execute files they shouldn't or strange errors/behaviour (like what you are experiencing).
I also believe this will also fix the issues you are having since the public folder is not being rewritten which is probably picked up by the Laravel router for some reason.
I don't believe the issue is with Lighthouse but with how you are hosting your Laravel application, try and see if that can be fixed and if the problem persists.

Problem when routing from outside a project to internal route automatically head to index.php

I have a project which I have to share external routes from it like so ..
ex: https://www.example.com/something
If I head to the root website it does not cause any problem and if I head to any internal route no problem causes.
The problem starts when I take a copy of a given route site inside the website and paste it to address bar or share a link to any resource when I enter the route the website automatically redirects to https://www.example.com/index.php and this causes a problem with some integration callbacks because it invalid it.
I think it's a problem with htaccess but I cannot identify the problem because I have a lack in experience with htaccess rules and how to manage it with server configs.
I tried to change the rewrite rules in htaccess but no result
success
I tried to find a config file inside the server that override none
to make it accept overriding but no result success also
This is my .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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule.* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTPS} !on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Laravel project links not working on heroku

I was given a laravel project I need to get up and running. I am new to laravel, but after allot of work, I believe I got everything configured properly and I deployed the project to heroku.
When I do artisan serve on my guest machine in my laravel project and go to the given url everything works fine all the links works.
But I deploy it to heroku and my index page shows but none of the links work.
I get:
Not Found The requested URL /register was not found on this server.
It seems that running php artisan serve kinda activates the links, but how do I make that happen on heroku???
I should note the app is using blade.php files
What am I missing???
This is in the /resources/views
My _htaccess inside my public folder is as follows
<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>
I tried adding RewriteBase / doesnt help.
I also tried changing htaccess to:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Laravel url parameter returning 404 once hosted

I'm developing a Laravel website. Everything is working fine on localhost. But once hosted online with 1&1, when I add a parameter in the route, it's returning an error 404 (not found).
In 1&1 the root url is redirecting to the file "public" of my laravel project.
And the .htaccess in this public file looks like that :
<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>
Does someone know what could be the problem ?
Try running the following artisan commands on your host:
php artisan optimize
php artisan route:clear
If you don't have access to run these commands, you can call them in code using Artisan::call('optimize') etc.

403 forbidden error when trying to install script on sub-directory

I have my own server which I run a few sites from. I have sub-directories that link to full domains (/music points to -> www.music-site.com)
My problem is I am getting a 403 forbidden error with a script I have installed to another sub-directory.
.htaccess file is as follows:
<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]
If it makes any difference, the script I am trying to install is based on laravel and bootstrap frameworks.
Does anyone know the issue?

Categories