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
-
Page redirected too many times
Hello, How can we solve the following error : This page isn't working ** redirected you too many times.** It's very frustrating. I have cleared the cookies. Still, the problem persists. Thanks
Technical SEO | | Johnroger0 -
301 redirects for all urls - legal dispute
The website in question is a very high traffic website with substantial credibility in it's subject matter (sorry, can't share more details) that delivers an overwhelming majority of traffic from SEO, much of which is new visitors. A legal dispute has resulted in both parties agreeing to forward a percentage of the total URLs to alternative websites (only 1 website for each party). All URLs for the domain will be forwarded elsewhere. It does not make sense to me that the "sum of the parts" will be as strong once the redirects are implemented but I am looking for feedback. It is fair to say that the alternative domains of each party are no where near as strong as the domain being "parted out." Will the SEO juice be distributed to each domain in full? Will both parties lose out substantially? Feel free to ask for clarifications and I'll do the best I can given the legal parameters. Thanks.
Technical SEO | | ReachMaineAgency0 -
Missing 301 redirects
I just had a developer friend call me in a panic, because they had gone live with a new site and found out (the hard way) that they had missed some pages on their 301 redirects. So the pages are appearing in Google but serving 404s. Ouch! So their question was: other than running a report for 404 errors in something like Screaming Frog, is there a way to hunt down ONLY pages serving 404s, then export to CSV so they can be redirected? Anyone got any tricks up their sleeve?
Technical SEO | | muzzmoz0 -
Redirect typo domains
Hi, What's the "correct" way of redirecting typo domains? DNS A record goes to the same ip address as the correct domain name Then 301 redirects for each typo domain in the .htaccess Subdomains on typo urls still redirect to www or should they redirect to the subdomain on the correct url in case the subdomain exists?
Technical SEO | | kuchenchef0 -
How to avoid a redirect chain?
Hi there, I am aware that it is not good practice to have a redirect chain but I am not really sure hoe to do it (on Apache). I have multiple redirects in a chain because on the one hand I had to redirect because the content of the site got a new URL and because on the other hand I changed from http to https. Thus I have a chain like http://example.com via 301 to http://the-best-example.com via 301 to https://the-best-example.com via 301 to https://greatest-example.com Obviously I want to clean this up without loosing any link juice or visitors who had bookmarked my site. So, I could make three separate redirects: http://example.com via 301 to https://greatest-example.com
Technical SEO | | netzkern_AG
http://the-best-example.com via 301 to https://greatest-example.com
https://the-best-example.com via 301 to https://greatest-example.com But is there a way to combine it? Can I use an "OR" operator to link the 3 conditions to this one rule? Any other suggestions? Thanks a lot!!!0 -
Rebranding / Redirecting
Hi I have a client who wants to re-brand their shopify clothing store under new domain name. Whilst still a clothing store its going to have different department structure and product pages and will hence be a different store/site. Is there anyway to pass any of the history/authority of existing site to the new one such as 301 redirecting the top level pages of existing site to nearest equivalent pages of new site etc or best to just redirect the old site domain to the new ? Cheers Dan
Technical SEO | | Dan-Lawrence0 -
Where to put 301 redirects in Magento?
I will be changing the URL structure in a magento store from "base/category/subcategory/product" to "base/product" which means i have to make over 1000 URL 301 redirects so our old links still work. Should i put the redirects in a .htaccess file so they stay intact no matter what or should i just put them in with all the other rewrites (in Magento 's URL rewrite manager)? Thanks
Technical SEO | | tilenkrivec0 -
301 Redirect Questions
I have a site I built on a wisiwig editing platform that will not allow a 301 redirect. The site has already been remade and I need to point it to another domain. To do the redirect, can I change it to another domain host that will allow a 301 or will that make me loose the authority of the site? I may not be able to move the content of the site. Please help.
Technical SEO | | photoseo10