How to set up htaccess to redirect all URLS to new domain?
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, , , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :So I have domain http://example.com.
I want to setup htaccess to redirect all of these variations
http://www.example.comhttp://example.comhttps://example.com/111http://example.com/222
...
basically EVERYTHING on this domain I want redirect to
http://www.newexample.com
How to set it up properly in .htaccess file?
All domains on same server.
Path needs not to be kept.
This guide from Apache should help: http://httpd.apache.org/docs/current/rewrite/intro.html
But for something you can copy and paste, see this cheatsheet but drop the $1 from the Rewrite Rule.
It's easier for me to post the code than to explain:
RewriteEngine on
RewriteCond %HTTP_HOST ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.newexample.com/ [R=301,L]
If that doesn't work, then your hosting company is restricting the settings that you can set in .htaccess and you'll need to call support to get it straightened out.
If both of your domain is on same server, on each request your server needs to work twice, one for handling with htaccess, another for serving site from correct address/domain.
What if you could do this directly from domain provider.
Redirecting to new domain using DNS settings
Most of domian provider let's you redirect domain preserving url and with header 301 or whatever you wish to.
I recommend you check with your domain provider, go to olddomain.com's setting, instead setting up A record of the domian, choose redirect option. Enter newdomain.com and forward all query strong and path as well.
This will save tons of request from being hit on your server, and your DNS might cache new path automatically.
Check if you can implement this solution, would be really good.
Comments
Post a Comment