How can I setup my .htaccess file to route to https:// in an angular app? - angularjs

I've seen some related access but they seem to affect the routes themselves. Shouldn't I just be able to update the initial load to be https and then everything else would flow from there?
My site is setup like this:
/Root
*client
-app files
-index.html
-htaccess
*server
-server.js (express, node)
In the .htaccess file. I have:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
What am I doing wrong? The .htaccess file apparently has no result? I want it to redirect to https:// when a user visits www., the root domain, or http://
Thank you for any help. Much appreciated.
Update: I've found another post that says this should work for me:
##Force SSL
#Normal way (in case you need to deploy to NON-heroku)
RewriteCond %{HTTPS} !=on
#Heroku way
RewriteCond %{HTTP:X-Forwarded-Proto} !https
#If neither above conditions are met, redirect to https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Unfortunately, it does not. Here is the post: How to redirect to HTTPS with .htaccess on Heroku Cedar stack

Apache redirection (using .htaccess) using a node server doesn't seem to work well together.
Stop Apache. Integrate redirection within your node express server file. Restart as a node server (sudo node server).

Related

Whats the best way for reactjs web app in production server

First, I planed deploy a reactjs website to production server by Apache.
But when I searched the thing in google, it showed me many way to serve a reactjs web app
For example:
Pm2, or just simple by using next start (i'm using nextjs)
So, is Pm2 or next start is good enough for production server.
or the traditional web http server (apache, nginx)
Many thanks
Personnally, I use a simple apache server which deserve react like this
DocumentRoot /www
<Directory "/www">
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>

Sonata admin missing css files

Working on a site with php 7.2, Symfony 4 and Sonata admin 3.
In dev, on my machine, everything works fine, the site itself, and the two admins (user and content).
I have put everything on the final server (unfortunately, file by file, no console with S4 ! so, no "composer:install"...).
Still on dev, the site works fine, all functionalities.
But when I try to use the admin page, I only get a non-formatted page. None of the assets (css and js) seems to work!
However the source code are identical, on localhost and the distant site...
Can anyone help me
Edit : I found where the issue comes from : it's linked to .htaccess.
The http address I use ends in /public/index.php. I use .htaccess to shorten it and when using the .htacces redirection I can't get the assets of the admin page, while it works fine without redirection.
Is there something I should change in my .htaccess code ?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php
</IfModule>

AngularJS navigating to a route gives 404 in Apache

When loading a page using Angular an Apache myserver.com everything works fine, when going to a subroute from the main page myserver.com/credits by clicking a link it'll work as well.
However, if I try to go directly to myserver.com/credits from the browser navigation bar it'll return a 404 error message:
I'm aware that by working with node I can configure this so that it does work, however, my company website runs in an apache server which I have no access to.
I could make it so the server redirects to the main page myserver.com like so:
.htaccess
ErrorDocument 404 /index.html
However the optimal resolution would be that going to myserver.com/credits works outright.
Is there a way to make Apache behave this way? And if so, how?
The answer that solves this question can be found here:
https://stackoverflow.com/a/22740184/1224232
I have flagged this question as a duplicate. I have tested it and it works perfectly.
Special thanks to Kevin B for directing me to the answer, and to Rajasaur for providing the answer.
Created a .htaccess file in root directory if not exist.
then add the following code in it
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# not rewrite css, js and images
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /index.html?path=$1 [NC,L,QSA]

Cakephp not loading css and js files

I seriously can't understand what is going on here. I just uploaded my web app from localhost to new domain-name on Windows IIS Server. When I try to access the web app, CSS files and images are not loaded and I get the following error:
"CssController could not be found."
I don't understand why it is doing this.
Although I've written code like this in my default.ctp:
echo $this->html->css('generic');
CSS files are placed in:
app\webroot\css
I have searched on Google and have tried everything, I even uncommented the line:
Configure::write('App.baseUrl',env('SCRIPT_NAME')); in core.php
But I still cannot get this to work. Please help me to resolve this issue.
Double check that you have all the .htaccess files in place.
Also making sure /app/webroot/ has its .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Your request is trying to get the css file from /css/ but i'm thinking you don't have the proper .htaccess files in place to route it to the webroot and not to a controller!
also check if mod_rewrite is enabled
Edit: and then I saw the IIS part, you need some IIS equivalent to mod_rewrite
In this article you find all the information required for successfully run CakePHP web applications under Microsoft IIS web server: http://bakery.cakephp.org/articles/filippo.toso/2008/01/29/cakephp-on-iis
Here is a related question about getting cake to work on IIS: CakePHP 2.2.2 not working on Windows IIS7

Setup subdomain in new app directory with Cpanel cakephp

I have working domain.kz with cakephp (Cpanel hosting)
www/app
www/cake
www/index.php
how can i setup admin.domain.kz to (app2)
www/app
www/app2
www/cake
www/index.php
The way you want it - will be very difficult; you'll have to change several file/folder paths in several places. Instead, why don't you try to create an admin folder where you've the full cakephp application for admin.
So the resulting folder structure would be like this:
(domain.kz)
www/app
www/cake
www/index.php
(admin.domain.kz)
www/admin/app
www/admin/cake
www/admin/index.php
Then you'll have to point your subdomain (admin.domain.kz) to /www/admin.
Now assuming that you've configured your domain and subdomain correctly, if you try to browse your domain, it'll work with no issues but if you try to access your subdomain, it'll give you a 500 error. DON'T WORRY. It is expected.
The primary .htaccess file is forcing all requests served by primary webroot (www/app/webroot) folder. You'll have to change your primary .htaccess file (www/.htaccess) like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^admin\.domain\.kz$ [NC]
RewriteRule ^ - [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Notice that, I've added two lines which tells that if you're trying to access your subdomain, stop rewriting; otherwise rewrite as usual. Cheers!!!
If the cake apps are totally separate but share a cake library then the following might work:
You could use cPanel's 'Addon Domain' feature, once the DNS has been set up for admin.domain.kz. Instructions can be found here.
Set the document root of the addon domain to the www/app2 folder.
Then just make sure that CAKE_CORE_INCLUDE_PATH in www/app2/webroot/index.php points to ../../../cake

Resources