What should I do to fix redirect in cpanel - redirect

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

Related

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.

Redirecting full URL including directories

I'm migrating to a new website.
I want to be able to redirect everything from the old website to the new website in the following structure.
Example 1:
http://dev.website-old.com/abc/123
to
http://dev.website-new.com/abc/123
Example 2:
http://dev.website-old.com/abc/123/xyz
to
http://dev.website-new.com/abc/123/xyz
How do I accomplish this?
This rewrite redirect all requests (1:1) from dev.website-old.com to dev.website-new.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?dev\.website-old\.com [NC]
RewriteRule (.*) http://dev.website-new.com/$1 [R=301,L]

Redirect users from www.mysite to mysite

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]

OpenShift Redirect Loop between www and non-www

I'm experiencing an infinite redirect loop when I try to access my site. The redirect loop seems to be between the non-www version and the www version.
My DNS has a URL Redirect set for http://domain.tld to www.domain.tld. Then www.domain.tld has a CNAME record for app-namespace.rhcloud.com.
For the app I added the alias www.domain.tld
I've also tried to add an alias for domain.tld, but that doesn't help.
Is there something I'm missing? Thank you very much for your help!
I'm hosting a laravel 5 project on openshift. www and non-www are tricky but I finally got it working with a simple 2 part solution...
since you can't use non-www for a cname, make it an A-record to 174.129.25.170 and they will add the www. That's all they seem to do. Weird, I know.
Use this in your .htaccess It seems to work better in cloud situations.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I found the issue. It was due to a redirect from www.domain.tld to domain.tld that was caused by a rewrite rule in the .htaccess file:
<IfModule mod_rewrite.c>
#RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
Removing this resolved the issue.

How do I use .htaccess to force www. while using Zend Framework

I want to force a www. prefix on my website by using a .htaccess 301 redirect. I am currently trying:
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
Which normally works, but I am using Zend Framework which causes all requests to be redirected back to http://www.mysite.com/index.php regardless of the initial request.
For example...
http://mysite.com/blog,
http://mysite.com/contact,
http://mysite.com/blog/this-is-my-article,
Will all be redirected to http://www.mysite.com/index.php
However, if I initially request a specific file, such as...
http://mysite.com/some-file.htm
The redirect works properly, redirecting to http://www.mysite.com/some-file.htm
In first time, don't forget to enable the rewriting ("RewriteEngine on").
The last line is important if you use Zend Framework.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteRule !\.(pdf|php|js|ico|txt|gif|jpg|png|css|rss|zip|tar\.gz)$ index.php
Now the url...
http://mysite.com/some-file.htm
... redirect to http://www.mysite.com/some-file.htm but use the index.php
Don't forget to ignore sub-domains when re-directing to www.
http://www.theblogaholic.com/2011/01/16/force-www-using-htaccess-except-for-subdomains/