.htaccess redirect all files/folders after www.website.com/ - apache

Hi I am currently moving a site to new hosting, previously they had lots of folders/files in the document root which i have moved to another server i.e. www.website.com/foldera/test.zip or just www.website.com/file.mp3 now on hosting.website.com/file.mp3
because these url's are still in circulation i need to redirect all files to the new location so if the old link is clicked it will re-direct correctly.
They have a large amount of files/folders. Please advise on the best way to do this?
Thanks

Just add this to the htaccess file in the document root of your old website:
Redirect 301 / http://hosting.website.com/
Or, if you'd rather use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$ [NC]
RewriteRule ^(.*)$ http://hosting.website.com/$1 [L,R=301]

Related

how to redirect a subdomain with child directory to new url using htaccess

I have a old website which used subdomains for each pages, i'm moving to new site and want to redirect the most of the links to the new pages.
I searched a lot but didn't find anything.
For instance i will be redirect this url to this:
blog.test.com/12/09/test-2 to test.com/blog/test-2
How it possible?
I tried this
or just simply redirect all the blog.test.com with whatever query they have to the new page?
blog.test.com/whatever?whatever to test.com/blog
You can use this code in your DOCUMENT_ROOT/.htaccess file of test subdomain:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(blog)\.(test\.com)$ [NC]
RewriteRule ^\d{2}/\d{2}/(.+)$ http://%1/blog/$1 [L,R=302]

force SSL for single .html page without php or anything else just using .htaccess

After several hours of trying a myriad of suggestions for .htaccess I have given up and decided to ask here.
I have a single html page that needs to be served via SSL. It is a single file with the .htm extension and it contains no php whatsoever. If anybody accesses this page via typing it in or clicking on a link from a non SSL page, I want that person to be redirected to or shown the SSL version of that page. Only https://example.com/myfile.htm should be allowed. The rest of the site can go without SSL, just this one page needs it.
Please help.
Try this in your .htaccess file.
RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule ^myfile\.htm$ https://www.example.com/myfile.htm [R=301,L]
Try:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^myfile\.htm$ https://example.com/myfile.htm [L,R]
SSL for HTML only page / SSL for JavaScript only page:
If anyone needs to set SSL (HTTPS) for page that uses html only (without PHP, nodeJS etc.) just put .htaccess file in the same folder as index.htm page.
Content of the .htaccess have to be:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I had trouble finding how to, so I think that this thread is the best to hold this answer.

301 Redirect from Magento to new store

I have a magento store set up at www.mysite.com/store/ - this is a Magento store and I want to redirect everything to a new domain www.mysiteshop.com.
I've put a .htaccess in the root of the Magento directory so that anyone who comes to it get redirected to the new store domain.
I don't need to redirect visitors who come to www.mysite.com.
RewriteRule (.*) http://www.mysiteshop.com/$1 [R=301,L]
But I need to make some changes as to how it works.
First, if they visit www.mysite.com/shop/alarm-clock.html I need to redirect them to www.mysiteshop.com/products/alarm-clock.
I also want to still be able to access the old admin area so if I could not redirect the url www.mysite.com/shop/index.php/admin/
If your htaccess file with the mysiteshop.com rule is in the /store/ directory, then you'll need to create another htaccess file in the document root (this is where you end up if you go to http://www.mysite.com/) in order to handle redirects for /shop/:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/shop/index\.php/admin
RewriteRule ^shop/(.+)\.html$ http://www.mysiteshop.com/products/$1 [L,R=301]
Or, you can place the rules in the htaccess file in the /shop/ directory:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/shop/index\.php/admin
RewriteRule ^(.+)\.html$ http://www.mysiteshop.com/products/$1 [L,R=301]

.htaccess 301 redirect from old domain to new domain while structure of pages and url are same

I want to redirect http://olddomain.com to http://newdomain.com for my all urls..keeping the page on new domain same.
What i mean to say is URLs such as below
http://olddomain.com/home/category/page.html
http://olddomain.com/home/mybook/page2.html
http://olddomain.com/login
should be 301 redirect to the new newdomain but same pages, like below
http://newdomain.com/home/category/page.html
http://newdomain.com/home/mybook/page2.html
http://newdomain.com/login
this is what i have in my .htaccess currently
RewriteEngine on
RewriteCond $1 !^(index\.php|img|public|robots\.txt) [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]
Please help me to do this cleanly and exlpain things in details since i am new in this.
also does someone know how much time search engines might take to move away from the references of my olddomain? i mean the old-domain urls in search queries should be replaced by new-domain urls... n old domain should go away from search engines.
Add following code at the beginning of .htaccess -
RewriteEngine On
# Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^another.olddomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
Much simpler:
Redirect 301 / http://newdomain.com/
Replace your .htaccess file with that one line OR if you have access to it, put it in the apache conf file(s) for your old domain (I place it following the DocumentRoot directive).
See Redirecting and Remapping with mod_rewrite for more info.
I usually add the following codes in .htaccess in the old website
#Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
This above code will redirect all links to new domain, you don't have to do anything, each link and images redirect to new domain link.
Beside this we have to tell Google when your site moves
If you've moved your site to a new domain, you can use the Change of address tool to tell Google about your new URL. We'll update our index to reflect your new URL. Changes will stay in effect for 180 days, by which time we'll have crawled and indexed the pages at your new URL.
Here is the link for this https://support.google.com/webmasters/answer/83106?hl=en
I have done this for 2 to 3 sites without losing seo as well. It does work.
Thanks
Tried to do
LoadModule rewrite_module modules/mod_rewrite.so
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
</IfModule>
But did not worked the way it should, was just trying to point my localhost to newdomain.com.
But when I hit localhost still it does not point.

Limiting access to one directory when on subdomain

Howdy, I need to do the following:
allow access to sub.domain.com/directory from www.domain.com (linking to an asset)
prevent access to sub.domain.com/* (Return a 404 page when user hits subdomain directly
Is this possible using htaccess and, if so, any pointers on how to accomplish it?
Thanks
Using .htaccess you might want to look up htaccess and regex tutorials as they are of great help.
Stop sites from hotlinking is what I assume you are referring to therefore: you need to enable mod_rewrite and add this to the .htaccess file in the domain's root directory (with a little of what you learn):
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://www.domain.com/noHotlink.gif
This should point you in the right direction towards how to do it.