Redirecting all sub-sub pages to another subpage using htaccess - apache

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/

Related

htaccess redirect only specific page, not subpages

I have a website with following url structure:
www.example.com/products
www.example.com/products/productA
www.example.com/products/productB
I need to redirect www.example.com/products to www.example.com but www.example.com/products/productA and productB should still be available.
Does anyone have an idea?
At the top of your .htaccess file, using mod_rewrite:
RewriteRule ^products$ / [R=302,L]
I've used mod_rewrite here, as opposed to a mod_alias RedirectMatch directive since I assume you are already using mod_rewrite later in the file to rewrite your URLs. It is preferable not to mix redirects/rewrites from both modules.
Reference:
https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriterule

301 htaccess redirect from old path to new path

I want to the following redirect 301 to happen on .htaccess file for my site.
From:
www.mysite.com/view/2133/page.html
To:
www.mysite.com/node/2133
The 2133 will be a dynamic number like a * (eg www.mysite.com/view/*/page.html)so it will work for all my other pages.
Try:
RewriteEngine On
RewriteRule view/([0-9+]) /node/$1 [R=301,L]
For an explanation see: URL Aliasing, Redirection, Rewriting and Reverse Proxying using Apache HTTPD

.htaccess redirecting only pages with no subfolder

I am using .htaccess to redirect pages from an old website to a new site. The URL structure has changed completely, but thanks to a SEO person I have a complete list of URLs I have to redirect and take care of.
My .htaccess looks like the following:
Options +FollowSymlinks
RewriteEngine On
Redirect 301 /some-guy http://www.new.domain/kontakt/
Redirect 301 /some-other-guy http://www.new.domain/kontakt/
...
Redirect 301 /de/some-page http://www.new.domain/some/subpage/
Redirect 301 /de/another/page http://www.new.domain/nice-page/
Of course the URLs can be even longer and contain query strings and stuff like that. The new website has a different URL structure and does not need query strings and nothing.
Now, while the first two redirects work perfectly, every redirect which contains a subfolder fails to redirect to the target location. The last URL for example redirects to
http://www.new.domain/de/another/page
What am I missing here?
Try
Redirect 301 ^de/another/page http://www.new.domain/nice-page [L]
I got it working now with little modifications to Anup Saunds code (and therefore using mod_rewrite).
I used the following structure which seems to work fine with all links I have and sets the status code for search engines.
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^what/ever/your/path-is(.*)$ http://www.new.domain/oh-what/a-nice-path/ [R=301,nc]

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

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]

.htaccess for redirecting rss feed

I want to redirect each URL ending with /feed to mysite.com/rss
My old subscribers have links such as mysite.com/something/feed or mysite.com/otherthing/something/feed and I want to redirect them all to mysite.com/rss now.
How would I go about generating the redirect in .htaccess?
You can use either mod_alias or mod_rewrite, whichever one is more suitable with whatever other rules/settings you have. Put this in the htaccess file in your document root:
RedirectMatch 301 /feed$ /rss
or:
RewriteEngine On
RewriteRule /?feed$ /rss [L,R=301]