Redirection Plugin and Regular Expressions
-
I am using Wordpress and the Redirection plugin.
I have recently launched a new site and while it was in development, a lot of broken pages were created and indexed. These are terminating in 404s.
I am looking to redirect all traffic from: /replay/postname/ to the homepage. When I use this regular expression:
Source: /replay/*
Target: /
it removes the /replay/ but leaves the postname.
Any idea how I could redirect all traffic inside of /replay/ to the homepage?
Thanks a bunch, Josh
-
wow, fantastic. Very helpful - really appreciate it!
-
A bit more detail:
/ begins the regular expression - from here on we're replacing what evaluates as TRUE
replay looks for the string "replay" in the URL
\ is an escape character, meaning evaluate what follows as is. We need to escape because / has a specific meaning in regex, but we want it to actually look for a slash
/ follows the escape character, so now its searching for "replay/"
. means any character other than line-break
- means this part is present 0, 1 or many times. You want "anything after replay/" so we repeat the . regex with a ... arriving at (.) The parenthesis tell the * which part its supposed to work on
-
That did it! Thanks!
Do you mind explaining that syntax for me?
-
In regular expressions the / character denotes the end and beginning. Try this instead:
source: /replay/(.)*
target: /
The source can be parsed as "start at replay, escape a / into the string, then any other characters or none at all."
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Doubt with geoip redirection
Hi everyone, I managed an international site with subfolders for for the countries (us, uk, fr, ...). The homepage has a geoip redirection to the specific user country. I've checked some old posts like this ones but it's not cleared for me if I should do a 301 or a 302 redirection. https://moz.com/community/q/geoip-redirection-301-or-302 https://moz.com/community/q/geoip-and-redirects I know that the best approach it’s avoid automatic redirections but it's not a possibility for me. So please, can you help me to decide what type of redirection should I use?
Technical SEO | | dMaLasp0 -
301 redirect: canonical or non canonical?
Hi, Newbie alert! I need to set up 301 redirects for changed URLs on a database driven site that is to be redeveloped shortly. The current site uses canonical header tags. The new site will also use canonical tags. Should the 301 redirects map the canonical URL on the old site to the corresponding canonical for the new design . . . or should they map the non canonical database URLs old and new? Given that the purpose of canonicals is to indicate our preferred URL, then my guess is that's what I should use. However, how can I be sure that Google (for example) has indexed the canonical in every case? Thx in anticipation.
Technical SEO | | ztalk1120 -
Temporary Redirects - Trackback & Feed
Under my MOZ account I'm getting a bunch of temporary redirect warnings. Most of them are blog post with a /feed or a /trackback . I know the trackback URL's are coming from blogs where people have commented because it brings up a Trackback URL | Comments RSS Feed section. I'm not sure how to make this /trackback work. The only line of code in my editor that says trackback is h3#postinfo,
Technical SEO | | jampaper
h3#comments,
h3#respond,
h3#trackbacks,
#respond h3 {
margin: 0;
}0 -
.htaccess redirects
I've done some research but can't find a good answer to this question. Here's my situation: Site redirects from example.com to www.example.com just fine. However, it doesn't work so well for internal pages. My site incorrectly redirects (non-www) example.com/page2 to www.example.com when it should instead go to www.example.com/page2 So I need a method to redirect non-www internal pages to www versions. Currently I have this in my .htaccess - do I need to modify the rules? RewriteEngine on
Technical SEO | | 3plains
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L] Thanks0 -
Redirecting root to /default.aspx
Hello, I have a client who's home page redirects to /default.aspx - what are the possible SEO impacts of this? As the home page redirects to /default.aspx and does not load under both there does not seem to be a duplicate content issue. Also the redirect should carry over most of the link juice from the home page to /default.aspx therefore are there any negative SEO "side effects" of this set-up? Thanks in advance!
Technical SEO | | RikkiD220 -
301 redirects
Hello. Our site was recently rebuilt, and we switched from using index.php in all the urls to not using it at all. We also changed the names of many of our pages. So the urls have been renamed from "example.com/index.php/old_page_name/" to "example.com/new-page-name/". While we were at it, we changed from "_" to "-" as our word separators in the urls. In the .htaccess file, we have a small block of code that strips out "index.php/" from all requests. This code redirects a request for "example.com/index.php/old_page_name/" to "example.com/old_page_name/" For your information, the code that strips out "index.php/" is: RewriteCond %{THE_REQUEST} ^GET.index.php [NC]
Technical SEO | | nyc-seo
RewriteCond %{THE_REQUEST} !/uSZWTLna/.
RewriteRule (.?)index.php/(.*) /$1$2 [R=301,L] Then we have 301 redirects from "example.com/old_page_name/" to "example.com/new-page-name/" QUESTION 1: Is this two-step redirect approach okay, or would it be better to skip the separate index.php stripping code and simply have 301 redirects that include "index.php" in the urls? QUESTION 2: Will we lose some of the benefit of the links that have to pass through a 301 redirect? QUESTION 3: We have 50 or so redirects. Will this affect performance of the site? How many redirects does it take to start affecting performance? Thank you!0 -
Do I need redirects for a .asp to a .htm?
We move to a new site and some of the pages were widgets.com/test.asp, do I need to redirect that to widgets.com/test.htm? It is the same url just the difference between .asp and .htm
Technical SEO | | EcommerceSite0 -
Relocating Real Estate Agent - Redirect?
I'm a real estate agent relocating to a new market. I have a fairly strong site in TN. How do I transfer as much juice as possible to my new site in FL? I don't want my new site in Florida to rank for TN keywords.
Technical SEO | | DanBoyle760