I have a wesite with WebSocket to subdomain.
I used .htaccess to redirect all transportation to another port.
Here is my .htaccess file:
DirectoryIndex disabled
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule (.*) ws://localhost:8080/$1 [P,L]
RewriteBase /
RewriteRule ^(.*)?$ http://127.0.0.1:8080/$1 [P,L]
While https works fine. wss doesn't.
The error from chrome:
socket.io.js:1706 WebSocket connection to 'wss://subdomain.domain.com/socket.io/?EIO=4&transport=websocket&sid=f5j9zNNk8-gStdnxAAA8' failed:
Without any more information
The weird thing is, my browser do https request every second and get the correct data.
Here is my Network tab:
Please help me figure it out.
Related
I would like to redirect all traffic on my site to HTTPS except for the ads.txt file. Note it's to a file e.g. domain.com/ads.txt and not a sub-folder such as domain.com/all-files-in-here/
I have tried the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} !/ads.txt
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This isn't working according to the testing tool at https://adstxt.adnxs.com
Could someone tell me what I am doing wrong please?
Kind regards
James
I know this is an old post but I was unable to find an acceptable answer for what Google Adsense require.
"Make an ads.txt file reachable via both HTTP and HTTPS"
This works for me...
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/ads\.txt
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
When the protocol is HTTP you want to convert every url to HTTPS except "/ads.txt".
When the protocol is HTTPS you dont need to convert any url.
This provides the required outcome to have ads.txt load on both HTTP and HTTPS.
Cheers
Greg J
I am currently using the following .htaccess code to rewrite:
http://force-t.fr to https://www.force-t.fr
http://www.force-t.fr to http://www.force-t.fr
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.force-t.fr$
RewriteRule ^(.*) https://www.force-t.fr/$1 [QSA,L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://www.force-t.fr/$1 [R=301,L]
Now, I need to add two exceptions :
All url starting with force-t.fr/iot/ needs to be accessible via http or https.
IE8/XP users needs to access the www.force-t.fr website in http only
(SNI is not supported by IE8/XP and my certificat is not working for them.)
I don't know how to do this and spend two hours searching without success.
While looking for an answer for the question above I have encountered this script as a solution(I would like to have my website on http except of a few pages like login, register,manage etc.):
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# force https for /login.php and /register.php
RewriteCond %{HTTPS} =off
RewriteRule ^(login|register)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# don't do anything for images/css/js (leave protocol as is)
RewriteRule \.(gif|jpe?g|png|css|js)$ - [NC,L]
# force http for all other URLs
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/(login|register)\.php$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This exact example should work on my server, but it works only partially, meaning, it redirects all pages to http, but I am unable to open login.php or register.php. The webbrowser states that these pages include redirect loop and they can't show up. By no means I am not an expert on mode_rewrite or htaccess so I would appreciate any help.
edit:
I have followed the suggestions and run mywebsite with chrome plugin. I discovered that in the page login.php has redirect loop http->https->http etc. (The only other redirection on that page is when the user is already signed, but it doesn't seem ike a couse for this loop). I have tried also different codes for setting SSL and this one works:
# Rewrite Rules for example.com
RewriteEngine On
RewriteBase /
# Turn SSL on for payments
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/login\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Turn SSL off everything but payments
RewriteCond %{HTTPS} on
RewriteCond %{SCRIPT_FILENAME} !\/login\.php [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
And this one is working correctly, but it has only one exception for https and I would like to have more of them(around 6). Has someone any idea why the first script is not working? or how to modify the second one in order to have more https websites?
Thanks
I had similar problem, this is what worked for me.
In your httpd.conf, under virtual hosts, make sure you have both:
ServerName domain.com
ServerAlias www.domain.com
BOTH in VirtualHost *:80 AND VirtualHost *:443
I am getting a redirect error: Firefox has detected that the server is redirecting the request for this address in a way that will never complete. I have the following inside my .htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}/test/ [L,R]
when I load http://www.mysite.com or https://www.mysite.com I get redirected to:
https://www.mysite.com/test//test//test//test//test//test/......
It appears that the RewriteCond does not recognize https as being on and continually loads that rewrite rule.
Why would this condition not fail when https is set?
The following seemed to fix my problem:
RewriteCond %{ENV:HTTPS} !on [NC]
I am developing a PHP based website. I made it live with HTTP URL and URL rewriting.
let suppose my domain is www.abc.com
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$
RewriteRule ^([^/]*)/([^/]*)$ index.php?%{QUERY_STRING}¤t_event=$1 [L]
And I access my site as http://www.abc.com/article it works fine.
Now my client installed SSL certificates on server and I want to change URL to HTTPS but accessing https://www.abc.com/article gives me 404 error.
Please guide me how can I make my above rules work with HTTP/HTTPS both.