How to redirect .htacces to another alias - .htaccess

How to remove only "-home" from URL?
From:
https://www.example.com/arbipedia-comentarios-a-lei-de-arbitragem-home/conteudo-exclusivo-arbipedia/1314.html
to:
https://www.example.com/arbipedia-comentarios-a-lei-de-arbitragem/conteudo-exclusivo-arbipedia/1314.html

You can use the following redirect to remove -home substring from uri :
RedirectMatch ^/(.+)-home/(.+)$ /$1/$2
This will redirect http://example.com/foo-home/bar to http://example.com/foo/bar .

Related

301 Redirect URLs starting with a specific keyword

I need to redirect all URLs staring with a specific word using RedirectMatch.
Let's say I need to redirect any URL that starts with the keyword "pdf" should be redirected to the base URL.
Requirement:
http://www.example.com/pdf -> http://www.example.com/
http://www.example.com/pdf-444-abc -> http://www.example.com/
http://www.example.com/blog/pdf-abc-1234 -> must not redirect
http://www.example.com/images/web/pdf/1234568.jpg -> must not redirect
I have used the following 301 redirect rule and it redirects all above examples.
RedirectMatch 301 /pdf(.*)$ http://www.example.com/
How can I achieve this?
For matching only starting characters use '^' (caret)
RedirectMatch 301 ^/pdf(.*) http://www.example.com/

How to 301 redirect via htacces

I'm trying to setup a 301 redirect for the following link:
https://www.domain.de/aaa/bbb/
and i wanna redirect it to:
https://www.domain.de/ccc.html
and thats what i already tried:
Redirect 301 /aaa/bbb/ https://www.domain.de/ccc.html
RewriteRule ^aaa/bbb/$ /ccc.html? [L,R=301]
and
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /aaa/bbb/ /ccc.html
</IfModule>
none of them worked for me. Any hints for me?
You can use this:
RedirectMatch /aaa/bbb/(.+)$ https://example.com/$1.html
Short explanation :
The regex capture-group (.+) captures everything after /aaa/bbb/ and saves the captured value in $1 variable and then we use the $1 in the destination url.
This is doing a temporary (302 default status) redirection from /aaa/bbb/foobar/ to /foobar.html . If you want a permanent (301) url redirecton, simply add a 301 status code to the directive ie: RedirectMatch 301 pattern destination .

Htaccess redirection for url ending with dot(.)

I have a website and there is a booking page , booking.php . I want to redirect people who is typing dot(.) at the end of url to correct url .
For example some one type example.com/booking.php. then I have to redirect to example.com/booking.php How can I do this?
I tried and it is not working
Redirect 301 http://www.example.com/appointment.php. http://www.example.com/appointment.php
You can use RedirectMatch for that.
Check this code :
RedirectMatch 301 /appointment\.php\.$ /appointment.php
Reference : https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirectmatch
OR
You can use mod_rewrite to redirect it.
Check below code :
RewriteRule ^(.+)\.php\.$ $1.php [R=301,QSA,L]
Reference : http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

ERR_TOO_MANY_REDIRECTS [duplicate]

I want to make a redirect 301 from an old ulr to a new url.
old url: /php/zend-framework/captcha-codigo-anti-spam-zend-framework
new url: http://www.demo31.com/blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
In .htaccess I make this redirect like this ...
RedirectMatch 301 /php/zend-framework/captcha-codigo-anti-spam-zend-framework http://www.demo31.com/blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
But I've got the error "ERR_TOO_MANY_REDIRECTS".
What am I doing wrong?
It looks like both URI's are on the same host (www.demo31.com), so when you use RedirectMatch, the part of the URI that matches is part of the redirect. Example
If I go to:
http://www.demo31.com/php/zend-framework/captcha-codigo-anti-spam-zend-framework
The URI is /php/zend-framework/captcha-codigo-anti-spam-zend-framework
The RedirectMatch directive matches the URI, redirects to:
http://www.demo31.com/blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
new URI is /blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
however, the RedirectMatch directive matches the URI again since it contaings /php/zend-framework/captcha-codigo-anti-spam-zend-framework
Try changing RedirectMatch to just Redirect. Or if you only want that specific URI to redirect (as opposed to something like /php/zend-framework/captcha-codigo-anti-spam-zend-framework/some/other/stuff also getting redirected, add a few delimiters:
RedirectMatch 301 ^/php/zend-framework/captcha-codigo-anti-spam-zend-framework$ http://www.demo31.com/blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
(the ^ and $
RewriteRule ^bad_url$ good_url [R=301,L]
Thx ! works for me

Extract some part of string and then redirect using htaccess

I want to extract some part from url and then redirect user to the page using htaccess like below
Original:
https://www.bosterbio.com/v/vspfiles/pdf/PA2036-1_DS.pdf
Extract the part after pdf/ and before _DS.pdf and then redirect to the following:
Target:
https://www.bosterbio.com/picokineDatasheet?sku=PA2036-1
Try :
RewriteEngine on
RewriteRule ^v/vspfiles/pdf/([^_]+)_DS\.pdf$ https://www.bosterbio.com/picokineDatasheet?sku=$1 [L,R]
you can also use RedirectMatch
RedirectMatch 301 ^/v/vspfiles/pdf/([^_]+)_DS\.pdf$ https://www.bosterbio.com/picokineDatasheet?sku=$1

Resources