403 Forbidden when I try to access my website without www - http-status-code-403

I'm facing a strange problem.
I can access my website with :
https://www.example.com
http://www.example.com
https://example.com
But I can't access to it by tipping :
http://example.com
example.com
I try to put an .htaccess to redirect the non www to the www version but it doesn't work.
# Redirect to www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Do you know why ?
Thanks.

The problem might come from your DNS settings.
You need to create a record for your domain name without the leading "www.": it should be an A record with the name of “#” that points to your server IP

Related

Can't map https://www.example.com to https://example.com

Trying to set up .htaccess to send requests for http://www.example.com to https://example.com. Using an .htaccess procedure like this
RewriteEngine On
RewriteCond %{REQUEST_SCHEME}#%{HTTP_HOST} ^http#(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]
does the right thing when dealing with http://www.example.com (going to https://example.com) and either https://example.com or http://example.com. However, when I try using https://www.example.com, Chrome throws up "ERR_SSL_PROTOCOL_ERROR".
My SSL certificate apparently does not cover subdomains of example.com, so perhaps that's the problem? Is there any way to avoid unnecessary SSL processing on the www.example.com domain?
Edit: Problem was that www.example.com did not exist. After creating the sub-domain, the following htaccess code works:
# Map www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
#
# Ensure we are using https:
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
[Still not sure whether the scope of my SSL cert. is an issue.]
Solution was to add the subdomain www.example.com. (See edited question.)

htacess rule for forwarding from www to http

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http:\/\/example.com\/$1 [L,R=301]
I create the above rule to avoid site duplicacy
Also
http://www.example.com is pointing to http://example.com
but the issue i am facing is i am not able to move any urls like
http://www.example.com/xyz/abc is not pointing to http://example.com.
Please help

How to redirect subfolder from non-www to www

I have a wordpress and set with http://www.example.com/ and I want to redirect from the non-www to www one.
The follow sample works for http://example.com to http://www.example.com,
but i also want the following redirection which doesn't work in the current implementation.
//subfoler
http://example.com/wp-admin/ to http://www.example.com/wp-admin/
//with querystring
http://example.com/?p=1034 to http://www.example.com/?p=1034
The current goes to 403 Forbidden, do you have any suggestion?
Should i work with .htaccess or 403 error page to perform simple redirection?
Here is my setting in the .htaccess
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
thanks
More information about my site.
I have used cloudflare and set the following value to my site. Does it matter?
Type Name Value
A sample.com XX.xx.xx.xx
A www xx.xx.xx.xx
A * xx.xx.xx.xx

301 Redirect where 2 domains point to same IP?

I have 2 TLDs example.com and example.ie.
example.com and example.ie both point at the same IP address and pull the same content now we could get whacked with a ban hammer from Google for duplicate content so we want anyone accessing *.example.ie and *.example.com to be redirected to www.example.com the problem is as they are both pointing at the same server the .htaccess is the same thus I don't believe we can do the usual:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
So how do we go about creating a search-engine friendly 301 redirect from *.example.ie and *.example.com to www.example.com?
I would do it like this:
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]
That will redirect (statuscode 301 "permantly moved") every domain which is not www.example.com to www.example.com.
The 301 redirect you posted is just fine; the HTTP header of every request (nowadays) contains the name of the host.
As an alternative, you can use rel=canonical. It's not that urgent anyway, as duplicate content on just two domains is unlikely to be a problem.

.htaccess to require WWW for domain, but allow subdomain if existing with no hard coding

I'm trying to figure it out how to set up an .htaccess set of rules that would force the presence of the "www" in front of the domain if it is not initially specified, but at the same time, it will not have any effect if the an subdomain is pressent; all this without hard coding any domain name so that the script is portable around different servers and configurations.
EDIT:
I'm sorry I was not able to get this explained right in the fist place. So what I need is as follows:
http://example.com -> redirects to http://www.example.com
http://www.example.com -> does not redirect
http://subdomain.example.com -> does not redirect
This mod_rewrite rule should do it for second level domains:
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.org
RewriteRule ^ http://www.example.org%{REQUEST_URI} [L,R=301]
This will not redirect subdomains like mail.example.org

Resources