i created a react app using create-react-app , after finishing the development i runned ' yarn build ' then i uploaded the files in the build folder on the server using fileZilla ( i have a premium account on hostinger )
in my package.json i added the following line :
"homepage": "https://goinprod.com/",
my .htaccess file located in the public_html folder looks like this :
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:goinprod.com
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (www\.)?goinprod.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:goinprod.com
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW UPGRADE_INSECURE_REQUESTS:goinprod.com
Header always set Content-Security-Policy: upgrade-insecure-requests
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW UPGRADE_INSECURE_REQUESTS:goinprod.com
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:goinprod.com
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (www\.)?goinprod.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:goinprod.com
the home page looks fine but when i navigate in another page it show the following error
file structure on the server :
static ( folder )
asset-manifest.json
favicon.ico
index.html
logo.png
logo2.png
manifest.json
.htaccess.
precache-manifest.json
robots.txt
service-worker.js
my website link : https://goinprod.com/
it was a routing problem i just added the following code in the file .htaccess in public_html folder :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Related
I'm deploying my first project on Hostinger. It's a React app created according to the basic config given on reactjs.org. I have uploaded my entire folder to the server via FileZilla and am now trying to configure my .htaccess file but I am only getting 500 errors back. I put this file in my folder called react-portfolio but nothing works. The whole project is stored in the react-porfolio folder.
here is what I tested first
DirectoryIndex /react-portfolio/public/index.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ react-portfolio/public/$1 [L]
</IfModule>
here is the second file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Thank you
I want to host my react app in a subdirectory on my shared hosting account. Ie in the directory domain.com/mydirectory/. But when I type domain.com/mydirectory/ in the search bar it opens the index of the directory & not the React App itself.
I have already created a build version for my app. Hence the index.html file is at the root of the directory with the static folder & all the other contents that where created during the react-build script.
How can I make it work properly ? How can I configure my .htaccess file or what fix should I consider ?
You can try to add a .htaccess file in your React directory with that source code into it.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirectory
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Just copy and paste following in your .htaccess
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
I have an angular 2 app served on Angular 2. On the host, it is located at the document root and everything is working fine. I have an .htaccess file with:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Problem:
On my laptop, i have an Apache server (xampp) with document root as "
c:\users...\WebProjects
When i develop the site, i put the files in c:\users...\Projects\Projects1\dist
In this directory, i cannot get the website to work due to files/folders called not being in the root. ie Server is trying to load \css\app.css when it should be loading Projects1\dist\css\app.css
Can i write a specific .htaccess to be able to serve the app from that directory? (or something else without having to change the httpd.conf document root?)
thanks
you need to add the path in your .htaccess file and your index.html file like so:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your/path/here/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
In index.html, you need to update the base href aswell to reflect the path like so:
<base href="/your/path/here/">
And that should do the trick :)
Overview :
I would like to redirect the visitor on a default page(index.html) inside the directory structure to display when a directory is accessed using .htaccess file(as of now current directory index.html is loading).
But When I turn on $locationProvider.html5Mode(true) in my angular application getting below error.
Console Error :
Directory structure of Application :
public_html
--prod
--public
--app
--controllers
--directives
--services
--app.config.js
--index.html
--.htaccess
.htaccess
public_html => .htaccess :
DirectoryIndex prod/public/index.html
This .htaccess is used to redirect the visitors on a application page (prod/public/index.html) directly by using domain name, as of now when user visit the domain the current directory(public_html) index.html is loading.
public_html => prod => .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /prod/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /prod/public/#/$1
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/prod/$1 [L,R=301]
</IfModule>
prod => public => index.html :
<base href="/prod/public/">
Everything working fine If i removed $locationProvider.html5Mode(true) from my app.config.js file.So, when I comment out the $locationProvider code, everything works fine in # mode. I can get to /#/abc, etc. without issue. As soon as I put the $locationProvider parts back in, nothing happen.
Related issues on Stack Overflow with no success :
$locationProvider.html5Mode(true) issues
Angular html5 mode not working in apache
Inside public_html => .htaccess have this rule instead:
DirectoryIndex index.html
RewriteEngine On
RewriteRule ^/?$ prod/public/index.html [L]
then public_html => prod => .htaccess should have this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ public/index.html [L]
I have a laravel 5 installation. Works perfect.
.htaccess inside the public folder is default and works fine:
<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]
Inside the public (root) folder i have a folder named webapp
webapp includes a web version of my app build with angularjs and it needs push states
the ideal .htaccess inside the webapp folder would be:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# html5 pushstate (history) support:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</ifModule>
But it seems the .htaccess inside the webapp folder is not triggered.
I probably need to write the conditions and rules inside the laravel public folder. But i'm not sure how to handle this and in what order etc.
Can someone help me to combine the 2 .htaccess files into one to place inside the public folder.
This works for me:
bash-3.2$ cat .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301] #This creates a redirect loop for angular
# IF the resource does not exist as an actual directory...
RewriteCond %{REQUEST_FILENAME} !-d
# OR an actual file...
RewriteCond %{REQUEST_FILENAME} !-f
# AND is being requested from angular directory a/
# THEN send it to the angular routing file
RewriteRule ^(a/.*) /a/index.html [NC,L]
# IF the resource does not exist as an actual directory...
RewriteCond %{REQUEST_FILENAME} !-d
# OR an actual file...
RewriteCond %{REQUEST_FILENAME} !-f
# THEN send the traffic to laravel routing
RewriteRule ^ index.php [L]
</IfModule>
bash-3.2$