Redirect http to https google cloud load balance - google-compute-engine

I have created https load balance and added ssl certificate. site working with https:// but its not working http:// and getting 404 error
Added Headername as X-Forwarded-Proto and avlue as https in load balace header request
Added in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
is there any to redirect http to https to avoid 404 error?

At this time, there is no way to directly configure the GCP Load Balancer to redirect traffic from HTTP to HTTPS; however, there is a workaround to do this. Using Nginx, you can add the following string within the nginx configuration file:
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}
If you are using Apache, then you will have to do the following if you want to redirect the traffic using the .htaccess file:
Run either "sudo a2enmod rewrite" or "LoadModule rewrite_module modules/mod_rewrite.so" depending on the Linux OS you are running. This will enable
Edit or create the .htaccess file in the domain root directory with the following:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
You can find more details on the following link here.
There is also an internal request to have this feature added within GCP HTTP/HTTPS Load Balancers. I cannot provide an ETA on if/when it will be applied; however, you can follow the Public Issue Tracker (PIT) on the progress of the request.

Related

Why doesn't Chrome recognize my progressive web app?

I made a progressive web app with a nodejs backend. When I deploy it on my server, chrome does not recognize the app as a PWA. All other browsers do (firefox, opera...). This means I don't get the "download" prompt or the full screen view of my app.
It was working perfectly when it was deployed on heroku. I bought hosting and now it doesn't work. The main difference is that the app now runs on port 8443 because port 433 is used by a webserver. I looked on google and found that chrome only recognizes PWAs if they run on port 433. I asked the helpdesk and they told me to use a .htaccess file. I have not worked with one before and it does not seem to fix my problem. It automatically redirects to port 8443 but Chrome still does not recognize it as a PWA. This is the .htaccess I use:
SetEnvIf Request_URI "^(.*)" PORT=8443
RewriteEngine On
RewriteBase /
# CORS
Header add Access-Control-Allow-Origin "*"
# HTTPS
RewriteCond %{HTTPS} !=on
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# PORT
RewriteCond %{SERVER_PORT} !^%{ENV:PORT}$
RewriteRule ^(.*) https://%{HTTP_HOST}:%{ENV:PORT}%{REQUEST_URI} [L,R=301]
# RPROXY
# RewriteRule ^(.*) http://localhost:${ENV:PORT}/$1 [P]
I was wondering if the problem really occurs because the app runs on 8443 or if there is something else I don't know.
thanks!
I haven't tested this, but maybe using vhost and reverse proxy, so you can still serve your app on port 433 but reverse proxy the requests to your node server running on a different port.

Configuration to change the landing page on AEM Dispatcher

Is there any configuration we need to provide on AEM dispatcher settings for redirecting the domain to landing page?
For example,
user enters mydomain.com, the page should redirect to www.mydomain.com/index.jsp
Redirects cannot be done within dispatcher (except directing to 404 via filters).
To do that you have to use the vhosts section of httpd (per domain) and mod_rewrite plugin, best combine it with properly done http mappings inside CQ
Added the following configuration in httpd.conf file for the requirement.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/$ /index.jsp [R=301]
</IfModule>

Web Browsers Don't Pick Up SSL Certificate

I am setting up a ssl certificate for a website
http://www.wegetitall.ca
I have checked it with many different ssl checkers and everything is ok but neither chrome nor internet explorer pick it up. There is no lock sign in chrome and it doesn't even say the certificate is not secure, it just doesn't see it at all.
The certificate was bought from godaddy and more information about it can be found here: https://www.sslshopper.com/ssl-checker.html#hostname=www.wegetitall.ca
What could be the reasons it doesn't show?
I can see SSL connection with your website.
When you connect to your website, make sure you type https:// .... NOT http://
if the connection is http, you can redirect to https.
Check this thread for redirecting (it's based on a server with PHP running. Find the correct one that's applicable to you).
SSL is installed well you just need to redirect to HTTPS
Put following code in your .htaccess file.
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.wegetitall.ca%{REQUEST_URI} [R=301,L]

How to htaccess 301 redirect pages with a question mark in the url

I'm trying to redirect several pages that all have question marks in the URL.
I essentially want to redirect:
www.example.com/?attachment_id=456 to www.example.com
There's a ton of pages with differend id #s also.
I've tried a few things in htaccess with no luck..
Any ideas?
This is what I tried:
RewriteCond %{QUERY_STRING} ^attachment_id=[0-9]
RewriteRule ^/$ http://www.example.com/? [L,NC,R=301]
Why can't you do this? This code should redirect a URL like this www.example.com/?attachment_id=456
RewriteCond %{QUERY_STRING} ^attachment_id=[0-9]+
RewriteRule ^/?$ http://www.example.com/? [L,NC,R=301]
I made the / optional so that it can be used in Apache config or .htaccess. Also I kept the ? that you have in the redirect at the end of the RewriteRule to remove any query strings on redirect.
Your approach is next to perfect, just some minor corrections:
RewriteEngine on
RewriteCond %{QUERY_STRING} attachment_id=[0-9]+
RewriteRule ^/$ http://www.example.com/ [L,R=301]
The above is the version for the host configuration. note that you have to restart the http server after having made changes to the host configuration for them to get effective. To debug refer to the http servers error log file, especially at restart time.
If you have to rely on .htaccess style files, then the syntax for the rule itself must unfortunately be slightly different:
RewriteEngine on
RewriteCond %{QUERY_STRING} attachment_id=[0-9]+
RewriteRule ^$ http://www.example.com/ [L,R=301]
Such file has to be located in the main folder of the document root of the host. also the interpretation of such files must be enabled in the host configuration by means of the AllowOverride option.
In general you should always prefer the host configuration for such rules over .htaccess style files, but you need administrative access for that. .htaccess style files are notoriously error prone, hard to debug and really slow the server down.

Yii2 Advanced showing blank page

I am new in yii2, When I extract yii2 advanced content from an archive with "basic application template", "Yii 2 with advanced application template" and when I upload on server, it's showing blank page.
I checked yii2 basic it's working fine but only in case of advance template getting blank page.
The advanced template url is like: ../advanced/frontend/web/index.php?r=site
But getting Error: No input file specified.
on Apache Server, getting this error:
Not Found The requested URL advanced/backend/web/index.php was not found on this server.
I tried installing from composer as well as from an archive but getting same and no index file exists inside backend/web/ and frontend/web/.
Edit:
As Jichao suggested, I tried making subdomain which points to the advanced/backend/web, But still the problem is same.
Scrrenshot:
Add .htaccess file into the root directory of your project. You should do it manually after yii2 installation. Simple example of the .htaccess file:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ frontend/web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]