How to redirect "/%20rel="? - regex

The following redirect isn't working, I assume it's because of the characters in the page name (generated by Wordpress).
redirect 301 /%20rel= http://www.NewSite.com/OldSiteLandingPage.php
How can I get this 301 redirect from "/%20rel=" to work?

Replace your rule with this:
Redirect 301 "/ rel=" /

Related

how to write regular express for inserting at specific location?

I have long file containing lines like :
Redirect 301 /abcdef/ /ab/page1
Redirect 301 /abcdefasdff/ /abaff/page2
I need to insert or replace the following place(refer to *) with my domain for all the lines
Redirect 301 /abcdef/ */ab/page1
Redirect 301 /abcdefasdff/ */abaff/page2
result:
Redirect 301 /abcdef/ https://exmaple.com/ab/page1
Redirect 301 /abcdefasdff/ https://example.com/abaff/page2
can I use editor find and replace function to do this ?
Simply search for "/ /" and replace it with "/ https://example.com/"
for missing first slash " /"
Find -> Redirect 301 /([a-zA-Z0-9-]*) /
Replace -> Redirect 301 /$1 https://www.example.com/

Redirect 301 using regexp in .htaccess file

I am looking for a Regex to redirect urls like:
example.net/example-1
example.net/example-2
example.net/example-3
I have many URLs that have the same prefix, but a different suffix after example-.
I was trying around with regex.
Redirect 301 /example-.*$ http://example.net/example-overview
Redirect 301 /example-(.*)? http://example.net/example-overview
Redirect 301 /example-(.+)[/]?$ http://example.net/example-overview
Redirect 301 /([^/example-]+) http://example.net/example-overview
I can't get it work.
Normal redirects for example example-1 to example-overview are working fine.
EDIT:
Found a solution:
RedirectMatch 301 ^/example-(.+)[/]?$ http://example.net/example-overview
Redirect doesn't support regular expressions, use RedirectMatch for that.

Redirect pages which end in a nubmer

This is such a stupid question, I'm so close to solving it but regex is killing me – I'm using the JavaScript history api on various pages of a test.
Server side, I would like to redirect:
/test/1
/test/2
/test/3
All to
/test
So I am using
Redirect 301 /test/1 /test
Redirect 301 /test/2 /test
Redirect 301 /test/3 /test
This all works, but I would like to redirect
Redirect 301 /test/1000 /test
So, here is where I am going wrong, after some hacking, googling etc I'm using:
Redirect 301 /test/([0-9]+) /test
to replace all other lines of code, but it's totally failing. What's the line to match all /test/{number} so I can redirect them all at once?
Redirect doesn't support regex, but RedirectMatch does: httpd://apache.org/docs/current/mod/mod_alias.html#redirectmat‌​ch
It would read:
RedirectMatch 301 /test/[0-9]+ /test
Redirect directive doesn't support Regular Expressions. Instead you can try RewriteRule:
RewriteRule ^test/[0-9]+$ /test [R=301,L]
Looks like this expression will work for you.
/(?:\d*)?\d+/g
http://regexr.com/3e8bk

301 Redirect rule to cover multple cases

Is there any way I can do all the following ( and similar ) redirects with a rule
Redirect 301 brand/brand1 http://domain.com/department/brand1
Redirect 301 brand/brand2 http://domain.com/department/brand2
Redirect 301 brand/brand3 http://domain.com/department/brand3
Yes you can use RedirectMatch that gives your regex capabilities like this:
RedirectMatch 301 brand/([^/]+) http://domain.com/department/$1

How to 301 redirect from example.com/word.html or word-abc.html or abc-word.html to example.com

how to 301 redirect from example.com/word.html or word-abc.html or abc-word.html or url that contain "word" to example.com
Now I just do it manually with this simple code :
Redirect 301 /word.html example.com
Redirect 301 /word-abc.html example.com
Redirect 301 /abc-word.html example.com
I want do it automatically redirect from url that contain "word" to example.com
Thanks.
You should use RedirectMatch directive for its regex capabilities:
RedirectMatch 301 \bword\b http://example.com
This will redirect any UR that has word (with word boundaries) to http://example.com