Visitor's IP not getting forwarded in www-version of the domain - apache

I have a site where I am loading country-based dynamic contents. While Laravel's Request::ip() gets the proper(original) client IP if user visits the domain.com version, www.domain.com version gets the same IP for all visitors. I suppose it's the NS resolver server somewhere or something I am not aware of.
Is there a way to set the www version with redirects or something else so that $_SERVER['X-Forwarded-For'] or $_SERVER['HTTP_X_FORWARDED_FOR'] or $_SERVER['REMOTE_ADDR'] gets the original client's IP? It's a Cpanel, so I don't have all the independence on all the DNS components to forward everything as per my need with custom Apache or Nginx setup. I just need a bypass, so to speak, if any.

It is generally a bad setup if you allow clints to access a website with two different URLs i.e. www and non-www. This is because Google sees these as two different websites and logs stats for them separately. This is of course not ideal if you want good SEO. You should re-direct all clients to one URL, choose either www or non-www.
To achieve this you can create a redirect rule in your server configuration files.

Related

Node JS/Express 301 redirect from non www to www domain name

I have an application (Node JS/Express) hosted on Heroku that resolves fine using www, but when trying to access via https://richlew.co.uk/ or richlew.co.uk I cannot access my site. (The site mentioned is being used for testing purposes only, once resolved I can apply to production site).
Is there anything I can do server side to redirect non www to www? or does this need to be done at DNS level? I have tried setting ALIAS and going through the Heroku docs, not getting anywhere.
How can I resolve this?
The reverse is currently in vogue: traffic from www to this one without. Express applications do not like double domain names.
But going to the bottom of the topic: such redirections should be implemented by the web server.
You have to change redirect places.
https://support.dnsimple.com/articles/redirect-heroku/

Upgrading to SSL when site is public and all backlinks are Http

I use BlueHost for LearnInternetGrow.com and I have all www addresses being redirected to non www. I did this so that my organic search results would start with my domain name.
I recently set up SSL for the site but may not keep it in the long run.
I have backlinks that are hard coded with http://learninternetgrow.com. I want to redirect all types of variations of the address
(http://learninternetgrow.com http://www.learninternetgrow.com https://www.learninternetgrow.com)
to https://learninternetgrow.com. I want to do it this way so that if I get rid of SSL (which comes with a premium) I don't have to get Google to recrawl the site and redo all the backlinks.
I feel like my logic may be faulty. Has anyone used a 301 redirect to send all traffic to a secure version of their site. I started without SSL because the site is just a blog without any sign ins, but I read that SEO can get a boost if I use SSL. So this is really a test to see if the premium is worth the SEO bump. If it isn't I will get rid of it but I want to minimize the work necessary for this test.
Please let me know if you have done a similar test and how you did it. If you started with an http site and upgraded to TLS (SSL) how did you go about doing it without hurting your organic traffic.
The main questions is - When upgrading to SSL on WordPress, should one redirect to Https at the server level or change wordpress settings - WordPRess address URL to https:// or should I do both.
To get that "boost" your https but do done properly :
301 (permanent) redirect
Avoid mixed content
So you need to change the wordpress address in the settings to avoid mixed content, and add the 301 redirect directly in the server configuration if possible.
Wait at least 2 week before start looking for a boots. The boost will be small but don't forget :
https is not about SEO boost, it's about security of your visitor and integrity of your website (some ISP inject ads inside http websites...)

CDN for your entire site - when the origin server equals the supername

I am using a static site generator for my site, that means my entire site is static. All my resources and HTML files are referenced with the domain name prefixed, so that the CDN could be used.
But due to SEO concerns I disabled non-www access and redirect those to the www.domain.com variant. But now I cannot use a CDN apparently, because the origin server needs to be different from the supername.
Can a CDN be used for HTML files?
How can I deliver content through www.domain.com and use a CDN?
Can I give the CDN access to static.domain.com an an origin server, but deny access to other clients? Seems clumsy!
Any ideas?
Using Apache2.2 trying to use Level 3 CDN through my hosting company's site
depending what you are able to set on the CDN via your hosting company, the best way would be to override the host header on the CDN settings.
So, first let's look at your DNS settings:
www should point to the CDN
origin should point to your web server.
Now, on the CDN you set your origin to origin.yourdomain.com and add (I can't tell you if this is possible in your setup) a "http host header override" to www.yourdomain.com. In some cases it's implemented the other way around, so you would "force IP-Host" to origin.yourdomain.com.
In both cases, what you want to achieve is this:
when an end user requests www.yourdomain.com , it is resolved to the CDN
The CDN needs to fetch the content from your server, so it establishes a session on port 80 (assuming HTTP) to origin.yourdomain.com
Once the port is open, the CDN sends (amongst others) a HTTP Host-Header with www.yourdomain.com (this is the name based virtual host APache is seeing and evaluating).
That way you can set up your web server in exactly the same way as you would without a CDN.

Redirect all traffic to holding page unless logged in using .htaccess

I currently have a landing page setup on my domain.com which already receives traffic.
It will shortly be replaced with an online store. I need to upload this store to my live server in order to get it approved by the Merchant Facility Providers (MFP), and they require it to be accessible from it's final live location on domain.com in order to get approvals. I can't have users access this site until it has met approvals.
To accomplish this I wish to redirect all domain.com traffic to domain.com/holding/ except for MFP visitors.
Ideally this would be restricted by IP address, however MFP say they will need to grant a number of external parties access, and so IP address based access will not be acceptable and I should use passwords.
So my question is, how can I automatically redirect all traffic from domain.com to the holding page domain.com/holding/ unless they have logged in using a password at domain.com/login?
Users visiting the domain.com should not be asked for a password.
Will this be possible using just .htaccess/.htpasswd?
If so, can someone suggest how the logic of how it could work?
It's not possible using just an .htaccess file as all visitors would be presented with an HTTP standard authentication dialog if you enabled it on your domain.com site at the doc_root level.
Without knowing what scripting language you're using? (you've not indicated in the tags, just apache), but you could provide one index page that both acts as a landing page for users/potential-users as well as provide a login (username/password form) for MFP parties (wherever they may come from).
That way, you fulfil both needs without offending or discriminating in any way against any party.
As #nickhar has pointed out, there appears to be no way of doing this using just .htaccess.
My solution was to use a rewrite rule to redirect all requests from domain.com to domain.com/holding unless a specific cookie was set (checked for using RewriteCond %{HTTP_COOKIE}).
I set this cookie in a php script on domain.com/login, which was password protected using .htaccess/.htpasswd.
This is by no means a particularly secure solution, but is adequate for my purposes of keeping the site hidden from general traffic while the approval process is completed.

How can I redirect example.com to some.site.com/example while still showing example.com as the URL?

To restate the question:
I own the example.com domain name. My actual webhost (courtesy of a friend) is some.site.com.
I'd like people to be able to go to example.com and see some.site.com/example/. The thing is, I only want the URL bar to show example.com/whateverpage.html.
I've been studying and experimenting with mod_rewrite, but can't quite figure it out. Is this at all possible?
You could just host a basic web page with an iframe. How complicated is the site?
Who provides your dns - sometimes they have a web forwarding setting just for this.
And are you sure you can't just change the domain name on the site you are pulling from?
You need a CNAME record in your DNS that aliases some.site.com as example.com.
http://en.wikipedia.org/wiki/CNAME_record
If you or your friend don't have access to, or don't know how to modify the DNS server... Contact the HOSTING PROVIDER that is hosting the site, they should know how to make DNS CNAME records correctly. The wiki above has a few examples of what a CNAME record looks like.