Deploying Api Laravel and Front-end Vuejs - vuejs2

I'm trying to deploy my application on hostinger but I cannot. I've created an API with Laravel and the front-end with VueJS. Then, I have in my server folders:
public_html
index.html
static
api
public
.htaccess
Within my api folder, I have all laravel files to my API and in my .htaccess file in public folder I have this code:
DirectoryIndex public/index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L, R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,PUT,POST,DELETE"
Header set Access-Control-Allow-Headers "Content-Type, Authorization"
</IfModule>
For example, in my mydomain.com I get data from api.mydomain.com/api/some_url but I'm getting errors with cross-origin.
Can anybody help-me how to correctly set up my htaccess to comunicate my domain.com with my api.domain.com/api/some_url?

Related

htaccess header not applied on http file

I want to add HTTP response header using htaccess file, but it is not applied on the main file while all resources like css and img files gets that header. My htaccess file looks like this:
RewriteEngine On
Header always set test-header "value"
<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]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://myurl.goes.here/$1 [R,L]
</IfModule>
I tried to move "Header set" line across different places in my file but that didn't help.
Most likely the issue was because of using php fastcgi like described here. I'm using managed service so unable to change configuration, but adding headers in PHP code by using header command worked fine.

Single Page Application - .htaccess config

This is a VueJS application. I have a .htaccess file duplicated from any Laravel project like following;
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 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.html [L]
</IfModule>
This is perfectly working what i want. But when I activated comment SSL Redirect rule lines redirects to SSL but routes not running index.html file, for example I have a /login route, /login request working without SSL redirect but if I add SSL redirect lines not working. Please show me when I'm wrong.
Okay, I was configure my Digitalocean server manually, I've forget to enable rewrite in SSL virtualhost. That's a solution :)

Laravel: .htaccess rule for redirecting to https not working

I'm developing a laravel app and I need to force HTTPS for it.i've tried many other solutions that i found on the internet but none of them worked.is it possible that my app some how ignores htaccess rules?
i've already tried these solutions:
Laravel: how to force HTTPS?
here's my httaccess file :
<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]
# Handle redirect to Https
RewriteRule ^(.*)$ https://foody.ir/$1 [R,L]
</IfModule>

Angular 2 .htaccess

first for all i will say im a rookie in .htaccess and redirects.
The thing is, i have an angular 2 app working perfectly, but before that i was using some .php files to upload images to my server. But after i upload my .htaccess to solve the routes problem. Those .php are not working anymore.
This is my current .htaccess file.
<IfModule mod_rewrite.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Credentials true
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /home/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(upload|upload_cover)\.php
RewriteRule . /index.html [L]
</IfModule>
Im not able to find a solution :(.
Tree
/
-.htaccess
-images/
--content/
-upload.php
-main.bundle.js
-inline.bundle.js
-index.html
-main/
Could you try this simplified .htaccess? It redirects everything except when there is a matching directory or file.
<IfModule mod_rewrite.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Credentials true
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
</IfModule>

How can I redirect /api/* requests to another file?

I've been using Laravel for my API server, however it takes alot of resources for tiny tasks and we want to write our API in a different framework. Unless I completely seperate our API for scalability purposes, can I temporarily redirect all /api/* requests to api.php?
This is our folder structure:
app
vendor
public
index.php
.htaccess
api.php
This is our .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Excludes existing directories and files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Handle Front Controller...
RewriteRule ^ index.php [L]
</IfModule>
Just below R=301 rule you can add this rule:
RewriteRule ^api/ api.php [L,NC]