How to redirect to subdomain but then allow normal use of site - apache

So I have my site, www.domain.com.
For a week or so I want to direct all traffic going direct to the site to subdomain.domain.com, a little promo page about an upcoming feature. I want visitors to then be able to continue to the site as normal though after they've read it, so a continue to www.domain.com/index.php link.
How can I do that with in the htaccess file? Everything I've tried so far messes up when clicking the continue link.
Thanks

with .htaccess you could use a 302 temporary redirect, but it would be for a whole sub folder as far as I know.
Another way would be to redirect with JS/server site language to the subdomain, create a cookie, then redirect back to www.domain.com/index.php .
the 302 redirect is explained here: How do I redirect my site using a .htaccess file?
You would need to have a .htaccess for the root folder point to your subdomain

Note that this is only possible if you enable mod_proxy in the Apache config of domain.com otherwise URL will change after redirect.
Enable mod_proxy, 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
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^index\.php$ http://subdomain.domain.com/ [L,NC,P]

Related

In Apache how do I redirect all traffic going to scales.ejiw.com to scales.ejco.com?

Our old domain is scales.ejiw.com and our new domain is scales.ejco.com. For awhile I would like to run both in tandem with scales.ejiw.com just redirecting to scales.ejco.com. How do I set this up in Apache? Can someone please point me in the right direction?
I believe the best way to go is with a 301 redirection.
First of all because its search engine friendly and second of all cause its pretty easy to set up.
The best way to this with Apache is to edit the .htaccess file in the document root of your server and add the following lines:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^newdomain\.com
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
(Change the newdomain.com with your new domain of-course)
This way is will redirect 'www' and non 'www' traffic.
You can read some more about 301 redirections here.

Redirecting all sub-sub pages to another subpage using htaccess

I've a older site running in Apache Server which is already indexed in Google. I wish to redirect all those indexed links to my new site (As the older pages are not existing any more.)
So i wish to redirect all my sub-sub pages to my new root page
I've pages like follows
http://itdost.com/answer-now/Aerobics
http://itdost.com/answer-now/HTML
http://itdost.com/answer-now/Culture
I use the following redirect code for each one
Redirect 301 /answer-now/Engineering http://www.itdost.com/questions/
Redirect 301 /answer-now/Food http://www.itdost.com/questions/
Redirect 301 /answer-now/ASP http://www.itdost.com/questions/
But as the site structure is big, i wish to do it in a single line instead of writing a line for each redirect
Some thing like the following.
Redirect 301 /answer-now/% http://www.itdost.com/questions/
But the above code does not seems to work
In order to use regex better to use mod_rewrite which is more powerful than mod_alias.
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 /
RewriteRule ^answer-now(/.*|)$ http://www.itdost.com/questions/? [L,NC,R=301]
Try this:
RedirectMatch 301 ^/answer-now/ http://www.itdost.com/questions/

301 redirect not working

I made a subdomain, and I am trying to redirect a page from the original domain to the subdomain, with the same dir structure.
My original page is this:
http://www.comehike.com/outdoors/alaska_hiking.php
I put this rule into the .htaaccess file under comehike.com/outdoors/ directory:
RewriteRule ^outdoors/alaska_hiking.php http://hiking.comehike.com/outdoors/alaska_hiking.php [R,L]
But as you can see from visiting the original url, it doesn't redirect. Any idea why?
Thanks!
I use apache server.
That RewriteRule line works for me when I stick it in my .htaccess file, are you sure you have RewriteEngine On?

Redirecting PDF links from another domain using htaccess

We have two domains, let's call them first.com and second.com
We have a directory in second.com called reports, where all our PDFs are located, but we would like to these same PDFs accessible from first.com as well.
Can we redirect let's say first.com/reports/84839049.pdf to second.com/reports/84839049.pdf using htaccess?
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^domain\.com
RewriteRule (.*) http://domain1.com/$1 [R=301, L]
Yes.
redirect /requested/url http://second.com/result/url
http://httpd.apache.org/docs/1.3/mod/mod_alias.html#redirect
You may want to consider using mod_rewrite though, unless you asked for an .htaccess configuration specifically because you have no access to the server configuration and mod_rewrite is disabled or not loaded.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
http://webdesign.about.com/od/mod_rewrite/qt/site_redirects.htm
You'll need some grasp of regex for mod_rewrite, but it can make configuration of the redirects a lot faster than having to add a redirect for every file on your site(s).

How do I redirect a subdirectory and all files in it to the root using htaccess?

I'm trying to redirect all requests for a subdirectory and any files in it to the root directory, using htaccess. Currently I have redirect 301 /directory/ / But this redirects to the root with the file name requested appended to it.. ie www.domain.com/directory/this.html redirects to www.domain.com/this.html I don't want it to request the file at all. Is there a way to do this?
Thank you
Karl
You will probably have to use mod_rewrite. Assuming you place the .htaccess in the root directory, something like this should work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^name-of-subfolder/.*$ / [R=302]
</IfModule>
NB. I put 302, as it's always sensible to use for testing, 301 can make it a pain checking changes with your browser. Once it's working feel free to change to 302.