I want to redirect users to another domain name when they visit a certain directory in my website. For example; if the user visits /files then it would redirect them to www.myfiles.com. However, I would also like to do the same with subdomains so that when the user goes to /files or files.domain.com they are redirected to www.myfiles.com, for example.
How can I do this in a .htaccess file?
I hope people can understand what I am trying to describe.
use this
Redirect 301 /files http://www.myfiles.com
Try adding the following to the .htaccess file in the root directory of your domain.com site.
RewriteEngine on
RewriteBase /
#if either files.domain.com
RewriteCond %{HTTP_HOST} ^files\.domain\.com$ [NC,OR]
#or /files
RewriteCond %{REQUEST_URI} ^/files$ [NC]
#redirect to www.myfiles.com
RewriteRule ^ http://www.myfiles.com [L,R=301]
Related
I had a subdomain https://sub.rootdir.com/ which was migrated to the root domain and to a new host.
I want to redirect this subdomain to the root folder. The host told me to re-create the subdomain and then create an '.htaccess' file in which you can set redirection rules such as:
Redirect 301 / https://rootdir.com/
I have kind of no idea what to type in the htaccess file.
Can I please get help from you?
Create a .htaccess file in your subdomain folder and enter this code in;
RewriteEngine On
RewriteCond %{HTTP_HOST} !^rootdir\.com
RewriteRule (.*) https://rootdir.com/$1 [R=301,L]
I figured it out from other posts here tx
#mod_rewrite on
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.rootdir.com$ [NC]
RewriteRule ^(.*)$ https://www.rootdir.com%{REQUEST_URI} [R=301,NC,L,QSA]
I have multiple websites under the same web server.
My root structure is as following:
./
./site1/
./site2/
./.htaccess
I would like htaccess file to redirect to the correct folder.
If the user navigates to www.site1.com or site1.com it should rewrite the url to go to the ./site1/ folder and if the user navigates to www.site2.com or site2.com it should rewrite the url to go to the ./site2/ folder.
Is there any way to achieve this behaviour?
Thanks in advance.
Use following code in .htaccess file.
RewriteCond %{HTTP_HOST} ^(www\.)?site1\.com$ [NC]
RewriteRule !^site1/ /site1%{REQUEST_URI} [L,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC]
RewriteRule !^site2/ /site2%{REQUEST_URI} [L,NC]
I am trying to create a permanent htaccess redirect (301) from all files in one directory in one domain, to another domain sub-directory as follows:
Redirect all files in the following directory:
from: www.xxx.com/apps/forms/reg.html
to: www.yyy.com/apps/forms/reg.html
if someone entered the first url it should redirect to the second url
Please help on this to fix my redirection issue
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domain1.extension$ [NC]
RewriteRule ^(.*)$ http://domain2.extension$1 [L,R=301]
I'm trying to redirect this URL to a different subdomain but am getting a 404.
Need to redirect:
www.dustystrings.com/instrumentbuilding / XYZ
To here:
manufacturing.dustystrings.com/instrumentbuilding / XYZ
I have www.dustystrings.com on one server, and manufacturing.dustystrings.com on another server (necessity).
Basically, I want to redirect all www.dustystrings.com/instrumentbuilding/ queries to manufacturing.dustystrings.com/instrumentbuilding/
What's the right .htacess 301 code to do this? (Apache server)
This should work:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.dustystrings.com[nc]
RewriteRule ^.*/instrumentbuilding/(.*)$ http://manufacturing.dustystrings.com/instrumentbuilding/$1 [r=301,nc]
Redirect to www using htaccess redirect
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.newdomain.com with your actual domain name.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
I want to be able to use an .htacess file to allow the main domain only to be redirected, but not a subfolder of that domain.
Example; somesite.com redirects to something.somesite.com
but allow somesite.com/example through to what is in the /example directory.
I did see a question similar to this one but could not understand the answer well enough to want to use the code.
Try adding this to the htaccess file in somesite.com's document root:
RedirectMatch 301 ^/$ http://something.somesite.com/
Of if you'd rather use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} somesite\.com$ [NC]
RewriteRule ^/?$ http://something.somesite.com/ [L,R=301]