Website article .htaccess 301 redirect - apache

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.

Related

Redirecting some sub pages to another format page using htaccess

I would like to add 301 redirects to specific type subpage on my site which is hosted on LAMP server.
for example,
example.com/witcher-3-100309/player-count - example.com/witcher-3-100309?tab=player-count
example.com/dota-2-100209/player-count - example.com/dota-2-100209?tab=player-count
example.com/pubg-300100/player-count - example.com/pubg-300100?tab=player-count
Is there any way in htaccess to write a general rule for all these type URLs to redirect correctly instead of individual 301 redirect codes in htaccess.
Thanks in advance.
The following should do it
RewriteEngine on
RewriteCond %{THE_REQUEST} /.+\?=([^\s]+) [NC]
RewriteRule ^.+$ %{REQUEST_URI}?tab=%1 [NE,L,R]
This will redirect /foobar/?q=value to /foobar/?tab=value .
When you sure the rule is working ok you can change the R (Temp Redirect flag) to R=301 to make the redirection permanent.

htaccess redirect subdirectory to root

What rule can I add .htaccess that would give me the following result?
I want to redirect to the homepage any search that includes a certain directory. For example, when anyone tries...
test.com/example
...or...
test.com/example/something
...they end up at...
test.com
Most everything I have tried kinda worked but always ends up appending whatever was after the targeted directory to the domain after the redirect, for example...
test.com/example/something
...leads to...
test.com/something
This is not what I want. Thanks
Code I have tried...
RewriteRule ^example/(.*)$ http://www.test.com [L,R=301]
and
Redirect 301 /example http://www.test.com
UPDATE
This seems to fix it...
RedirectMatch 301 ^/example/ /
Redirect 301 /example http://www.test.com/
Thanks!
Try:
RewriteEngine On
RewriteRule ^example/ / [L,R=301]
or
RedirectMatch 301 ^/example/ /

url rewrites dynamic urls redirects - Magento

I'm looking for htaccess lines that do the following
Redirect old existing urls to new url (301)
Example
www.example.com/categorya/categoryb/product.htm
TO
www.example.com/product.htm
There can be more category parts, or less, it all has to go to /product.htm (Magento).
Who can help?
Try putting these rules in the htaccess file in your document root, preferably above any rules that you may already have there:
RewriteEngine On
RewriteRule ^(.+)/product.htm$ /product.htm [L,R=301]
Try:
RewriteEngine On
RewriteRule ^[^/]+/[^/]+/([^.]+)\.htm$ /$1.htm [L,R=301]

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]