.htaccess for redirecting rss feed - apache

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]

Related

htaccess 301 redirect not redirecting

tried several ways to make redirect, but not successfull
Redirect 301 /ru/pages/portfolio/ /ru/pages/portfolio/3/ [END,R=301]
or
Redirect 301 http://myssite/en/pages/portfolio http://myssite/en/pages/portfolio/3
and many others from internet, but all of them not working.
Need to redirect pages/portfolio to pages/portfolio/3 (for all languages - en, ru)
This is content of file
<IfModule mod_rewrite.c>
# Turn Off mod_dir Redirect For Existing Directories
DirectorySlash Off
# Rewrite For Public Folder
RewriteEngine on
Redirect 301 /ru/pages/portfolio/ /ru/pages/portfolio/3/ [END,R=301]
RewriteCond $1 !^(pma)
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Since you are already using mod_rewrite (for an internal rewrite) you should also use mod_rewrite for this redirect, rather than using a mod_alias Redirect. Different modules execute at different times during the request, despite the apparent order of the directives in the config file.
However, your example is unclear. The first example includes a trailing slash; the second does not? Is there a trailing slash or not?
Try something like the following instead after the RewriteEngine directive:
RewriteRule ^(en|ru)/pages/portfolio$ /$1/pages/portfolio/3 [R,L]
This excludes the trailing slash. And assumes "all languages" are just en and ru. This is also a temporary (302) redirect. Change to a permanent (301) redirect (if that is the intention) only when you are sure it's working OK, since 301s are cached by the browser. You will need to clear your browser cache before testing.
Redirect 301 /ru/pages/portfolio/ /ru/pages/portfolio/3/ [END,R=301]
:
Redirect 301 http://myssite/en/pages/portfolio http://myssite/en/pages/portfolio/3
Aside: Neither of these would have worked anyway. End flags like [END,R=301] are a mod_rewrite syntax, and do not relate to mod_alias (Redirect). And the URL-path matched by the Redirect directive should be a root-relative path beginning with a slash, not an absolute URL. See the Apache docs... https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect

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/

Website article .htaccess 301 redirect

I have a site in a folder called patients and my urls look like so:
http://site.com/patients/post-name
http://site.com/patients/articles/another-post-name
I want to redirect them all to a clean:
http://newsite.com/post-name
http://newsite.com/another-post-name
In other words, lose the /articles/ which sometimes appears and 301 to the new site.
Any help on how to do this with htaccess?
Edit your .htaccess in http://site.com server and put this(must be the first rule):
RewriteEngine On
RewriteRule .* http://newsite.com/ [R=301]
or
Redirect 301 / http://newsite.com/
Regards.

Rewriting from a SEO friendly URL to another SEO friendly URL on the same site

For our SEO needs in my company, we need to change some SEO URLs to another ones through 301.
Example:
/seo/keywords-1-2-3/ to /seo/mynew301page-1-2-3/
Is there some Apache rewrite rule that I can specify that certain URLs should be redirected to the new one?
As simple as this:
Redirect 301 /seo/keywords-1-2-3/ /seo/mynew301page-1-2-3/
The above will redirect ALL requests for URLs that start with /seo/keywords-1-2-3/ to /seo/mynew301page-1-2-3/. For example: /seo/keywords-1-2-3/something?say=hello ==> /seo/mynew301page-1-2-3/something?say=hello
If it has to be precise match (only /seo/keywords-1-2-3/ and not /seo/keywords-1-2-3/something, then use this one:
RedirectMatch 301 ^/seo/keywords-1-2-3/$ /seo/mynew301page-1-2-3/
The same, but using mod_rewrite:
RewriteEngine On
# broad (base) match
RewriteRule ^/seo/keywords-1-2-3/(.*)$ /seo/mynew301page-1-2-3/$1 [R=301,L]
# exact match
RewriteRule ^/seo/keywords-1-2-3/$ /seo/mynew301page-1-2-3/ [R=301,L]
You can do it n two ways:
.htaccess
httpd.conf
Mostly the .htaccess configuration method is used.
So you can use this code in your .htaccess file:
RewriteEngine On
RewriteRule ^/seo/keywords-1-2-3/ /seo/mynew301page-1-2-3/ [R=301,L]

Simple 301 redirect in .htaccess with query string does not work with Redirect directive

I am trying to redirect a single URL in a .htaccess file with Redirect:
Redirect 301 /index2.php?option=com_rss&feed=RSS2.0&no_html=1 /something/somethingelse/
I have a bunch of other similar rules which work using directory structure URLs, but this one refuses to get processed.
Redirect 301 /old/url/ /new/url/
Do I have to do anything special?
Thanks!
With Redirect you can only test for URL paths, or more specifically, URL path prefixes but not for the URL query. But you can do so with mod_rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} =option=com_rss&feed=RSS2.0&no_html=1
RewriteRule ^index2\.php$ /something/somethingelse/? [L,R=301]