why my laravel url not working when method is post
example the url api must be : http://localhost/PROJECTNAME/api/loginWeb
but when i click post button it always direct to http://localhost/api/loginWeb
but when method is get this okay. i use xampp
here is my htaccess
<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>
When we're using session based laravel setup, all the route generator functions(url(), route()) use hostname http://localhost as root url, not http://localhost/PROJECTNAME. To resolve this issue please do following changes in laravel app.
Define APP_URL in .env file as APP_URL="http://localhost/PROJECTNAME"
Go to RouteServiceProvider which is located at app/Providers/RouteServiceProvider and force laravel to use APP_URL as root url for your app.
public function boot()
{
parent::boot();
// Add following lines to force laravel to use APP_URL as root url for the app.
$strBaseURL = $this->app['url'];
$strBaseURL->forceRootUrl(config('app.url'));
}
Same issue occurred to me when I used same domain and a suburl to identify different projects.
Linux: Nginx serves multiple apps with two different locations
Windows: Multiple Laravel Applications Using Nginx - Windows
Related
I have two project folder, e.g. blog1 and blog2.
/var/www/html/blog1
/var/www/html/blog2/laravel
I am doing it as sub folder instead of sub domain.
blog1 folder consists of laravel project. Inside blog2 folder, there's is a folder name laravel which consist of laravel project.
this is my htaccess for blog1
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^(.*)$ blog1/public/ [L]
</IfModule>
Every time access too blog1 is simple, just https://website.com/login
Every time i want to access blog2 project, this is the link looks like https://website.com/blog2/login
htaccess inside blog2
<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 ^(.*)/$ / [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>
How can i make the link looks like https://website.com/blog2/ or https://website.com/blog2-sg/ or https://website.com/blog2-uk/?
My expected result
https://website.com/blog2/ will go to laravel login page
https://website.com/blog2-uk/ will also go to laravel login page
They will route to /var/www/html/blog2/laravel
Can i know is this doable and how to achieve it? Thanks.
I suggest looking in to Laravel Routes Subdomain Routing example:
https://laravel.com/docs/6.x/routing#route-group-sub-domain-routing.
This demonstrates how to use variable/dynamic parts in the URI.
Point all /blog2-*/ URIs to the Laravel application and let Laravel do further routing. I don't know your exact situation, but maybe the following redirect rule could help you out:
RewriteRule ^blog2-(.*)/ http://www.website.com/blog2 [R=301,L]
I am using an auth middleware in laravel. If I am calling the routes which does not have middleware('auth:api') then it is working fine But routes under middleware('auth:api') not working.
I have tried to update htaccess file and tried approx all the solutions, but no results.
My Route code is -
Route::group(['middleware' => 'auth:api'], function(){
Route::post('unregistered', 'API\InterestController#getUnregistered');
Route::post('new-campaign-listing','API\CampaignController#new_campaign_list');
Route::post('registered-campaign-listing','API\CampaignController#registered_campaign_list');
Route::get('past-campaign-listing','API\CampaignController#past_campaign_list');
Route::get('getcampaignhistory','API\CampaignController#getCampaignhistory');
Route::post('register-for-campaign', 'API\CampaignController#register');
Route::post('top-campaign-photos', 'API\CampaignController#topPhotos');
Route::get('user-detail', 'API\PassportController#getdetails');
//update profile
Route::post('update-profile', 'API\PassportController#update_profile');
//update profile
Route::post('shared-post-data','API\CampaignController#shared_post_data');
Route::post('vip-campaigns','API\CampaignController#vip_campaigns');
Route::post('vip_client','API\CampaignController#vip_client');
Route::post('add_user_interests', 'API\InterestController#add_user_interests');
Route::get('user-interests', 'API\InterestController#user_interests');
Route::post('update-user-interests', 'API\InterestController#update_user_interest');
//polls
Route::post('polls-for-vote', 'API\PollController#pollsForVote');
Route::post('vote', 'API\PollController#vote');
Route::post('contact-us', 'API\PassportController#contactmail');
Route::get('campaignpostimage','API\PassportController#campaignpostimage');
Route::post('firebase-token', 'API\PassportController#get_token');
//notifications
Route::post('notifications', 'API\InterestController#notifcations');
Route::post('unread_notifications', 'API\InterestController#unreadNotifications');
Route::get('coupons','API\CampaignController#coupons_list');
Route::post('redeem','API\CampaignController#redeem_points');
Route::post('campaign-detail','API\CampaignController#campaign_detail');
Route::get('rewards_history','API\CampaignController#rewards_history');
});
My function in passportcontroller is :
public function getDetails()
{
dd("hello");
}
My htaccess file code is :
<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}]
# RewriteCond %{HTTP:Authorization} ^(.*)
# RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# 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>
Even dd in controller is not printing. means API URL is not working
What is the error message?
Note:You should put the routes inside api.php
Please provide more info about how you are consuming your API?
if you are consuming the API's from different domain (Cross domain) than you will face the CORS issue, in that case you need to add the following package to your laravel application
and if you are on same domain tha you can follow the
documentation.
In my case this
git hub reported issue solved my problem
I am kinda new to Laravel and I am trying to do the next thing:
I have a Centos 7 running Apache and PHP on which I have different web apps running.
I have all apps in /var/www/html under folders and index.php links them all. Now i installed composer, Laravel and added a new Laravel project in /var/www/html/play/play1.
The problem is that when I try to access https://example.com/play/play1 I should get the Laravel index page (the one under public/index.php) correct?
Instead I get a directory with all Laravel project files.
If I access https://example.com/play/play1/public I can see the index page.
I've searched it over and I checked if AllowOverwrite all is present, if mod_rewrite is on. Inside public folder there is a .htaccess file.
Can anybody who dealt which such a problem help me please ?
Within the root of the project folder (where you see app/ resources folders etc) create a .htaccess file and paste the below:
<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
RewriteCond %{REQUEST_URI} (.+)/$
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>
Laravel's root directory should not be the one accessed publicly - you have to point to public/ directory (where the index.php and .htaccess are located).
So in your server config http://example.com/play/play1 should point to var/www/html/play/play1/public
I'm using a shared hosting server, I installed my first Laravel 5.4 application and everything is still working fine. A few days ago I installed another Laravel 5.4 application on a different domain, but same server, but when I try to access the URL, I get 500 INTERNAL SERVER ERROR.
Below is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I also tried the following, but same error:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
### Add two lines for fix error 500 ###
Options -Indexes
php_flag xcache.cacher 0
#######################################
# 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 moved everything inside your public_html folder which you should not do. Only files inside /public needs to be in public_html, hence the name public. The Laravel files should be placed higher directory where it is not accessible from the public.
Install Laravel with Softaculous, or with composer via SSH in /home/username/laravel
Move everything in /home/username/public_html folder to
/home/username/laravel
Move everything in /home/username/laravel/public to /home/username/public_html and delete the public folder after move.
Edit this file: /home/username/public_html/index.php
Change to require '/home/username/laravel/vendor/autoload.php';
Change to $app = require_once '/home/username/laravel/bootstrap/app.php';
Save this file and close window.
Edit this file: /home/username/laravel/server.php
Change to:
if ($uri !== '/' && file_exists('/home/username/public_html'.$uri)) {
return false;
}
require_once '/home/username/public_html/index.php';
Replace username with your hosting username. :)
I'm working in my first project with Laravel, it's a simple website with an admin panel:
In my "public" folder I have a directory called "admin" where I put all the styles and scripts corresponding to the admin panel. I've also defined a route in my app to handle the "admin" GET:
Route::get('/admin', 'Admin\DashboardController#index');
The problem is that since I have that "admin" folder in my public directory Laravel is ignoring the "admin" route I defined, so I can't access the proper controller. I'm suspecting it has something to do with the .htaccess but I'm not sure how to solve it. This is how my htaccess looks right now:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The issue is with the following line:
RewriteCond %{REQUEST_FILENAME} !-d
In your example this tells the web server not to send the /admin route to Laravel because it is a physical directory. If you remove that then the /admin route should work. This will however prevent browsing directly to a folder and getting a directory listing, which should not be a problem. The next line in the htaccess will allow you to link to asset files contained in your admin directory and not have them get processed by Laravel, so that should not be removed.
The newer version of Laravel also contains:
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
It should be updated to the following in order to avoid a redirect loop on the admin route:
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
So if using the newest version of Laravel, your htaccess file should look something like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
You cannot have a public directory with the same name as your route - otherwise how will Laravel know whether "/admin" is for the controller, or for the style etc.
You should store your admin style sheets etc under /assets/admin/*
For routes.php:
Route::controller('admin/dashboard', 'Admin\DashboardController');
For using assets in your public container you can now use:
<script type="text/javascript" src="{{Request::root();}}/assets/js/jquery.js"></script>
Where assets in the /public/assets/js/jquery.js
Hope this helps.