Work:
I am working on socket.io, and just hide a port number, and redirect domain to domain:{port}
I have 3 domains, all working from 2 years, and suddenly 1 socket.io stops accepting if URL comes from rewrite.
SERVER 1, example1.com/_____ rewrite with htaccess
.htaccess on server_1
RewriteRule ^socket2/(.*)$ ws://example_2.com:3000/$1 [P,QSA,L] #Working
RewriteRule ^socket3/(.*)$ ws://example_3.com:3000/$1 [P,QSA,L] #Not working
# Direct URL Working: ws://example_3.com:3000
On Server 3, example_3.com,
If i entered full URL "ws://example_3.com:3000" its working, if i write .htaccess rewrite rules on server1, then its not working.
My Diagnoses On server3:
Socket.io working 100% OK.
Socket connect and disconnect after milliseconds if URL from htaccess rewrite
I need help in finding out the exact issue and location. I just want to hide the Port number and rewrite wss:// to ws://
Related
I wanna make some redirect but for this i need to parse domain to send other domain.
My old domain url like this
http://olddomain.com/bg/some-name-part-421.html
http://olddomain.com/bg/some-name-1231.html
http://olddomain.com/bg/some-name-product-name-221.html
I want to redirect this to like this
https://www.newdomain.com/magazin/some-name-part.html
https://www.newdomain.com/magazin/some-name.html
https://www.newdomain.com/magazin/some-name-product-name.html
I try to redirect them like this on server block
rewrite ^(/bg/)([a-z-]+-[0-9]+)\.html$ http://www.newdomain.com/magazin/$2 permanent;
Not working well making redirect like this
http://www.olddomain.com/bg/chervena-borovinka-bioherba-3694.html
https://www.newdomain.com/magazin/chervena-borovinka-bioherba-3694
I want to delete also as last part of number and - but i dont know why not working well
Thats my .htaccess:
RewriteEngine On
RewriteRule "^bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "http://newdomain.com/magazin/$1$3" [R]
Dont forget to set the RewriteBase.
Heres the code: https://regex101.com/r/UdMqaQ/3/
Nginx
rewrite "^/bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "newdomain.com/magazin/$1";
I have installed Ghost, which needs nodejs to run. I'm doing this on an Apache Linux server via managed hosting. They kindly let me login with SSH access so I've been able to setup nodejs and Ghost using the standard installation instructions. I installed ghost to the root of my domain so in normal operation someone would go to example.com and it'll show them my blog. Well that's what I'd hoped.
However now when I've come to load Ghost in my browser I discover because I'm accessing it the way I am, and that Ghost doesn't do server configuration, I seem to need an htaccess file to be able to make the site reachable.
So, I have created this htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ http://127.0.0.1:65515/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:65515/$1 [P,L]
</IfModule>
With that saved to the root, if I go to example.com/ghost (the admin panel for Ghost) it works. Nothing wrong there, looks great. If however I try and visit the root, ie goto example.com, instead of showing me the index, it shows me index.js - that is, it literally loads the contents of Ghost's index.js file and displays it instead of parsing it and displaying the main index of the website.
IF however I go to www.example.com then it all works. So whatever the problem is it's because I'm not using www. in the domain.
I would prefer it to work both with or without the www in the URL though. I did try adding some solutions to redirect non-www requests to www.example.com to th ehtaccess but for some reason it still doesn't work (as in if I type example.com it doesn't redirect me to www.example.com).
I think maybe you should be using mod_proxy rather than mod_rewrite. At least, that's what I've used in the past. Apache will catch requests coming in on port 80 and then redirect them to port 65515 where your node server is listening.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
Like this:
ProxyPass / http://localhost:65515/
I figured it out. Wasn't anything to do with htaccess, or Ghost or nodejs or anything like it. No, instead the problem was the sodding server was caching the website. I discovered the setting to delete the cache and it all started working fine, so, this is now solved.
I've got a strange problem with https not redirecting to http. I need https://indudlgeinbrighton.co.uk to redirect to http://indulgeinbrighton.co.uk It's on a shared server and I'm getting a strange cross over with the https. When https is put in, it's loading information for a completely different website hosted on the server.
https://indulgeinbrighton.co.uk is the URL affected. I don't normally share the URLs I'm working on, but in the case I think it might be helpful to see what's going on. Where it's showing data for a website called Churchill, obviously this is a bit of a problem. I've tried putting in all the solutions provided on this page How do you redirect HTTPS to HTTP? into the root .htaccess but it's not working. The htaccess is working fine, because when I switched it to load the other way from http to https it worked fine.
I can only assume it's reading the htaccess file from the other site when it's looking at the https version. As I know which site it is, that's easy enough to locate, but what could I put in that htaccess file to redirect this particular url query without affecting https redirects on the other site?
Thank you.
try this in your .htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ http://indulgeinbrighton.co.uk/$1 [R,L]
this is for security measure
The page at 'https://indulgeinbrighton.co.uk/' was loaded over HTTPS,
but requested an insecure script
'http://churchillbrighton.com/wp-content/themes/brighton-hotels/js/avia.js?ver=3'.
This request has been blocked; the content must be served over HTTPS.
you can try to do this in PHP
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
or include always external files in https
I own a domain since long, just masking the names:
http://mydomain.com
Later I started using a subdomain on this domain for some project.
http://subdomain.mydomain.com
Those projects grew and now I have a structure like
http://subdomain.mydomain.com/project1
http://subdomain.mydomain.com/project2
http://subdomain.mydomain.com/project3/subproject1
http://subdomain.mydomain.com/project3/subproject2
http://subdomain.mydomain.com/project3/subproject3
http://subdomain.mydomain.com/project4
....
etc.
now I bought a new domain (shortdomain.com) where I plan not to move anything but everything should be accessible via redirects so everything looks like:
http://shortdomain.com
http://shortdomain.com/project1
http://shortdomain.com/project2
http://shortdomain.com/project3/subproject1
http://shortdomain.com/project3/subproject2
http://shortdomain.com/project3/subproject3
http://shortdomain.com/project4
...
etc.
So basically I need to do two things:
1. if anyone visits my old domain, redirect them the new naming structure. i.e. if someone loads http://subdomain.mydomain.com/project2 they should be redirected to http://shortdomain.com/project2
when a user loads/redirected to http://shortdomain.com/project2 this should actually load the content present at http://subdomain.mydomain.com/project2
So I will not manually migrate projects,codes and GBs of other data. I think this might be acievable by smart redirection only.
Just FYI:
1. I have full DNS control of both the domains
2. I am hosted on hostgator
3. I use cloudflare on the first domain and would like to continue using it
I think this might be acievable by smart redirection only.
No, redirection changes what's in the browser's location bar. If you redirect to shortdomain.com then the request will get sent to shortdomain.com, and have nothing to do with subdomain.mydomain.com anymore. If you redirect back to subdomain.mydomain.com, then the location bar in the browser will change as well.
What you really want to do is point shortdomain.com to the same server and document root that subdomain.mydomain.com is on. Then use this to redirect (either in htaccess file or server config):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://shortdomain.com/$1 [L,R=301]
If, for whatever absurd reason you can't point the shortdomain.com DNS to the same webserver that serves subdomain.mydomain.com, or can't setup that webserver to accept requests for the shortdomain.com host, you need to setup a proxy server. And it'll work something like this:
2 Webservers, server A (hosts subdomain.domain.com) and server B (hosts shortdomain.com)
Someone requests http://subdomain.mydomain.com/project3/subproject1
server A gets the request and redirects the browser to http://shortdomain.com/project3/subproject1
browser's location bar changes to new location
server B gets the request and reverse proxies the request back to server A
server A gets the request again but must recognize that it is a proxy and then serve the page instead of redirecting
As you can see, this is a horrendously ineffecient solution. It's also a high possibility that your hosting service won't allow you to setup proxy servers.
I have full DNS control of both the domains
With full control I assume you can enable mod_proxy as well on Apache web-server of shortdomain.com. Once that is done set it all up this way.
On subdomain.mydomain.com enable mod_rewrite and place this rule in Apache config OR DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule ^ http://shortdomain.com%{REQUEST_URI} [L,R=301]
On shortdomain.com enable mod_proxy, mod_rewrite and place this rule in Apache config OR DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^shortdomain\.com$ [NC]
RewriteRule ^ http://subdomain.mydomain.com%{REQUEST_URI} [L,P]
I have a (Joomla) site that is not currently pointing to a domain, but is sitting directly on my server IP (i.e.: http://176.158.165.1/~sitename)
Whenever I try to test my mod_rewrite, I get 404 errors. I have tested on another site on the same server, but it works 100%. Could this problem be due to the direct link to the IP address?
My .htaccess file is as follows:
RewriteEngine On
Options +FollowSymLinks
Redirect /google.html http://www.google.com
Thanks,
Dev
try:
Redirect 301 /google.html http://www.google.com
Try #2: (using mod_rewrite)
RewriteRule ^google\.html$ http://www.google.com [R=301,NC,L]
When working in a subdirectory, you need to add the directory name regardless where the htaccess file is placed:
Redirect /~sitename/google.html http://www.google.com
you can also use RewriteBase but to be totally honest, I never really figured out how to get that working, and I've been too lazy to sort it out.