Redirect subdomain to another subdomain - apache

i want to know how could i redirect subdomain to another subdomain and also different domain name
for example
i want to redirect subdomain
forum.example.com
to
forum.example.net
thanks

This code should work for you. you need to add a redirect to your .htaccess file.
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.net/$1 [r=301,nc
Another good, but lazy way is to use the following link, to genereate the code for you htaccesss generator

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^forum\.example\.com$ [NC]
RewriteRule ^ http://forum.example.net%{REQUEST_URI} [R,L]

Related

Mask subdomain using .htaccess

I want to mask my subdomain to a specific url on my main domain using .htaccess.
For example: https://sub.example.com to show the content of https://www.example.com/page/12345.
And the URL is still https://sub.example.com
I have got the following in .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com
RewriteRule ^https://sub\.example\.com https://www\.example\.com/page/12345
But if I go to https://sub.example.com, it shows content of https://www.example.com. Can't seem to figure out what's wrong. Please help!
Actually, you want to rewrite without redirecting. This requires enabling mod_proxy and mod_rewrite in Apache's httpd.conf.
Then, the rewrite should look like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
#only when there is query string and https on, if needed
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTPS} =on
RewriteRule ^$ https://www.example.com/page/12345? [R=301,NE,NC,L]
Reference:
What exactly does the Multiviews options in .htaccess?
htaccess rewrite without redirect
Apache: RewriteRule Flags

.htaccess rewrite to redirect domain.com to domain.net/subdirectory

I would like to redirect somedomain.tv to anotherdomain.com/tv and (if possible) keep the URL as somedomain.tv
My .htaccess so far:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^radiouas\.tv$ [OR]
RewriteCond %{HTTP_HOST} ^www\.radiouas\.tv$
RewriteRule ^/?$ "http\:\/\/www\.radiouas\.org\/tv" [R=301,L]
</IfModule>
# This simply redirects but does not keep the original URL
I have found many ways to do that when you have only one domain (e.g. domain.com to domain.com/blog). But in my case, I'm using two different domains...
How can I achieve that? Thanks in advance.

Why I cannot redirect in htaccess in this case?

I want to redirect the url of a javascript file by using htaccess:
From:
http://www.domain.co.uk/tracking/tracking.js
To:
http://www/domain.co.uk/Templates/domain.co.uk/tracking/tracking.js
After trying many things, now I've this one:
RewriteEngine on
RewriteRule tracking/tracking.js? http://www.domain.co.uk/Templates/domain.co.uk/js/tracking.js [L]
the problem is that with this configuration I only can access to the javascript code (the file) writing ......../tracking/tracking.js/ (with slash in the end, but I dont want it)
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.domain\.co\.uk)$ [NC]
RewriteRule ^(tracking/tracking\.js)$ http://%1/Templates/domain.co.uk/$1 [L,R=301,NC]

Editing a htaccess file to redirect site except for contents of one directory

hi so i want one site to 301 to another except for one directory and its contents
so if i put http://www.oldsite.com/whaterver I go to http://www.newsite.co.uk
so far I have
redirectMatch 301 ^(.*)$ http://www.newsite.co.uk
this redirect the whole site with no problems I added this above the first line
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/blog/
I think Im mixing to different modules together here..any help would be great thanks
dave
Use this code in your .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/ [NC]
RewriteRule ^ http://www.newsite.co.uk [L,R=301,NC]

htaccess redirect from domain1 to domain2

I know, this should be easy, but I cannot make it work.
I have 2 domains pointing to the same folder in an Apache server, bahiadivers.com and bahiadivers.cl.
I want to redirect bahiadivers.cl to bahiadivers.cl/es/ and change the address bar.
I try this (among a million things)
rewritecond %{HTTP_HOST} ^bahiadivers.cl [nc]
rewriterule ^/$ http://www.bahiadivers.cl/es/$1 [r=301,nc]
but didn't work... I mean, the URL is not changing in the browser address bar, but also the languge (/es/) is not working... how should I do this?
Thanks!
Try this for your .htaccess
# Apache configuration file
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
# If URL is www.example.com/es/Blah, use /Blah/
# Prevents needing to change existing links.
RewriteBase /es/
# Rewrite www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www.bahiadivers.cl
RewriteCond %{HTTP_HOST} ^bahiadivers.cl
# Rewrite any inbound URL Bits to http://bahiadivers.cl/es/...
RewriteRule (.*) http://bahiadivers.cl/es/$1 [R=301,L]
</IfModule>
That should do it.