Redirecting subfolders and keeping the same /forum and url $1 after - .htaccess

I need to redirect 3 subfolders from
https://www.website.com/forums/forum-group/forum/directing-subfolder-information-example
to
https://www.website.com/forum/directing-subfolder-information-example <-- this is what I want
I tried
RedirectMatch 301 forums/forum-group/forum(.*) forum/$1
but it puts /forum/forum
Any ideas on how to do it?

This should be working
RedirectMatch 301 ^forums/forum-group/forum/(.*)$ /forum/$1
If you want to do it using mod_rewrite
RewriteEngine On
RewriteRule ^forums/forum-group/forum/(.*)$ /forum/$1 [R=301,L]

Related

How to Redirect every link beginning with the same word in .htaccess?

I need to redirect a lot of urls beginning with the same word to a new link.
Exemple:
Redirect 301 /old-text-1/ /new-link/
Redirect 301 /old-text-2/ /new-link/
Redirect 301 /old-text-3/ /new-link/
Redirect 301 /old-text-4/ /new-link/
Redirect 301 /old-text-5/ /new-link/
...
Can I redirect all this links in a better way?
I tried:
RewriteRule ^/old-text(.*)$ /new-link/ [R=301,L]
but it doesn't work.
You need to remove the trailing slash when using RewriteRule directive in .htaccess context.
RewriteRule ^old-text(.*)$ /new-link/ [R=301,L]

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 .

Redirect 301 files from subcategory to root

I moved my prestashop from subcategory(/shop) to root and now,
to fix the 404 Not Found Errors, I have to redirect all pages
from
"example.com/shop"
to
"example.com"
(for example from "example.com/shop/skirt" to "example.com/skirt"). What do I have to add to .htaccess? thank you so much.
If you want to redirect
"example.com/shop/product-A"
to
"example.com/product-A"
try with
RewriteEngine On
RewriteRule ^shop/(.*)$ /$1 [L]
If you want to redirect the browser so that the new URL appears in the location bar, add an R flag in square brackets:
RewriteEngine On
RewriteRule ^shop/(.*)$ /$1 [L,R=301]
You can use the following Redirect in your htaccess :
Redirect 301 /shop/ http://example.com/
This will 301 redirect your subfolder to the root including all pages and directories from /shop to / .

htaccess 301 redirect /%C2%A0/

I am trying to do a 301 redirect via htaccess from http://www.domainname.co.uk/%C2%A0/ to http://www.domainname.co.uk/ but i can not get it to work
I am having a lot of trouble with the /%C2%A0/ any help with this would be great
thanks
Try:
RewriteEngine On
RewriteRule ^\xC2\xA0/?$ / [L,R=301]
Or if you have to use mod_alias:
RedirectMatch 301 ^/\xC2\xA0/?$ /

Redirect from one location with wilcards using htaccess

I need help with how to use the htaccess when a folder and any subfolders get redirected to a new url.
Example: http:www.mysite.com/events/a-name-of-an-event (the 'a-name-of-an-event' will vary)
to
http:www.mysite.com/fixtures/
You can use RedirectMatch directive in your DOCUMENT_ROOT/.htaccess file:
RedirectMatch 301 ^/events/ /fixtures/
OR using mod_rewrite:
RewriteEngine On
RewriteRule ^events/ /fixtures/ [L,R=301,NC]

Resources