Redirect users from www.mysite to mysite - redirect

We've been issued a new certificate for our website, but unfortunately without an alternative name for the www subdomain. Visiting the TLD without www works just fine.
Redirecting them via .htaccess doesn't work, probably because the initial connection isn't even made.
I've tried using this:
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} ^www.mysite$
RewriteRule ^(.*)$ https://mysite/$1 [R]
Is there any way to "force" users away from www or do we need to be issued a new (fixed) certificate for our domain?

Check this redirect (change example.com to your domain):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) https://example.com/$1 [R=301,L]

Related

What should I do to fix redirect in cpanel

Im trying to redirect one of my domain to the other one and added a redirect in cpanel with wild card redirect. It has added a line at the end of .htaccess file
RewriteCond %{HTTP_HOST} ^oldDomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldDomain\.com$
RewriteRule ^(.*)$ "https\:\/\/newDomain\.com\/$1" [R=301,L]
but its not working correctly if I go to oldDomain.com/about it will redirect to this page https://newDomain.com/cache/wp-rocket/oldDomain.com/about/index-https.html_gzip
what should I do to fix this issue?
I have tried godaddy forward domain

Redirect rule to allow sub.domain.com to only serve images

I need help with a redirect rule.
I created a subdomain sub.abc.com and set it's public_html to that of abc.com.
This means public_html is now accessible either by abc.com or by sub.abc.com .
I want to limit this so that sub.abc.com only provides access to images in wp-content/uploads any other requests to sub.abc.com should be redirected to abc.com/url/url .
Here is what i have tried creating
RewriteCond %{HTTP_HOST} ^cdn.example.com
RewriteCond %{REQUEST_URI} !^/wp-content/uploads/$1
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
so if the user is accessing cdn.example.com/wp-content/uploads/1/1/file.jpg then there is no redirect, but if they are trying to access cdn.example.com/post/post or cdn.example.com/anything-else then it will redirect to example.com/post/post or example.com/anything-else .
The following rule should work for you. Remember to put it at the of your htaccess or server.config file before others rules otherwise these rules may override it.
RewriteEngine on
#serve only images on abc.example.com
#redirect to main domain if request is not for images
######################
#if the host is "sub.example.com"
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
#and the request is not for images and /wp-content/uploads
RewriteCond %{REQUEST_URI} !/wp-content/uploads/?$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpg|png|gif|jpeg)$ [NC]
#redirect the request to main domain
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=302]
This will redirect your sub.example.com with request string to example.com if the subdomain is used for requests other then images .
Replace sub.example.com and example.com with your real domain name in the RewriteCond and RewriteRule above.
If this works and you are happy with the redirect then change R=302 to R=301 to make the redirection permanent.

JBoss and RewriteCond and RewriteRule

I need to redirect all requests that don't come from this domain ti-passis.rhcloud.com
and use https to http to avoid certificate error.
Example:
https://ti-passis.rhcloud.com/contato (should'n be redirected)
https://tetraimoveis.com/contato (should be redirected because of certificate error, once the certificate is for "*.rhcloud.com")
RewriteCond %{HTTP_HOST} !^ti-passis.rhcloud.com$ [RC]
RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteRule .* http:// %{HTTP_HOST}%{REQUEST_URI} [R,L]
The RewriteCond works alone, but if I put then together, nothing works.
Am I doing something wrong?
The correct way to do it is (though you likely figured it out by now)
RewriteCond %{HTTP_HOST} !^ti-passis.rhcloud.com$ [RC,OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteRule .* http:// %{HTTP_HOST}%{REQUEST_URI} [R,L]
You're basically just "Or"ing the expression. As per JBoss "'ornext|OR' (or next condition)
Use this to combine rule conditions with a local OR instead of the implicit AND."

ISPAI Rewrite 301 Redirects / SEO URL Canonicalization on Windows Server

I am new to working on a windows server and have been made aware that it is setup for ISPAI Rewrite.
I have tried creating a httpd.ini file and a .conf file with possible redirects but nothing is working.
Could someone show me how to create the correct file and then rewrite the following:
http://aspectexhibitions.co.uk/
Should redirect to:
http://www.aspectexhibitions.co.uk/
--
http://www.aspectexhibitions.co.uk/index.php
http://aspectexhibitions.co.uk/index.php
Should redirect to:
http://www.aspectexhibitions.co.uk/
Done...
[ISAPI_Rewrite]
#Redirect Non WWW to WWW
RewriteEngine on
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]
#Redirect index.php to root
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ http://www.aspectexhibitions.co.uk/ [NC,R=301,L]

htaccess redirect not working with some browsers

here is the htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NCL]
the first rule checks if you have www , and if not redirects to the www + https, the next rule checks to see if the client accesses the website via https, everything works, except on opera, opera redirects me to https://www.domain.com/https://domain.com/ like it puts the domain + request uri in {request_uri}, and i can't seem to make it work.Any suggestions on how to make this work correctly?
Edit :
IE is not working too.It just gives server error.
The redirect is done by Apache, so Opera is not guilty in this error. I tested your rules and got an error:
RewriteRule: unknown flag 'NCL'
Try this:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]