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
-
301 Redirect Review Nodes
I have a client who rents out vacation beach rentals. They currently have thousands of homes under management. Each property has its own internal reviewing platform. Reviews are not really intended to be viewed on their own, as in a stand alone page with just the review on it. The problem is that Drupal makes just about every type of node viewable on its own dedicated URL. I was just thinking about taking request to view stand alone reviews and 301’ing them to their respective property page, the context in which they are intended to be viewed. The website has about 2500 review nodes currently crawlable via Drupal that sit on their own URLs. Would there be a material impact to 301 them to their respective property page when any attempt to view them on their own is made to the site?
Technical SEO | | conversionpipeline20 -
One more redirect question
If there are two URLs like below: example.com/toys/batman-toys
Technical SEO | | IceIcebaby
example.com/birthday/batman-toys Both have the exact same everything, except URL key. The first example ranks for all KWs and search terms in the SEs. Does having the second page hurt my ranking potential for the first page? Should I redirect the 2nd page to the first or just leave it? As always, thanks for your help.0 -
301 redirect .htaccess
Hi guys I am working on some 301 redirects on an apache webserver and I'd like a bit of assistance in trying to get a specific type result: I want all addresses from domaina.com to be redirected to domainb.com in the same structure so domaina.com/folder/file will go to domainb.com/folder/file expect for 2 folders.
Technical SEO | | seobackbone
ie: DomainA.com --> DomainB.com
except domainA.com/folder1
and domainB.com/folder2 Can someone let me know how I can pull this off?0 -
URL redirecting domains
Hi Is there anything wrong/dangerous forwarding a clutch of domains to a sub page (landing page) on a different domain ? Say Brand X buys Brand Z and wants to close down Brand Z site but have Brand Z domain fwd to a landing page (explaining the company acquisition) on Brand X site. In addition Brand Z had a few related but unused domains forwarding to Brand Z doman & now also wants those fwd'd to the new landing page on brand X Since the reasons for doing this forwarding are legitimate company reasons relating to an acquisition i would have thought it should be ok but can anyone think of a reason why could be bad since i remember in the old days peeps used to redirect domains for seo reasons so worried fwd'ing a load of domains could cause some sort of negative flag with big G ? Also do domain redirects transfer the authority/juice from the old site/domain to the new destination page (new landing page on brand x site) similar to how a 301 redirect works ? Many Thanks Dan
Technical SEO | | Dan-Lawrence0 -
301 Redirects Not Allowed by Host
Not sure if anyone has an answer, but we have a client who has an ecommerce store with SBI! The client has a new site with a new store builder/host and wants to 301 redirect all of the old site's indexed pages to the new site. However, we were just informed by SBI! that 301 redirects are not allowed - even more, they don't even grant FTP access. Any brilliant ideas from anyone how we can get around this?? Thank you!
Technical SEO | | roundabout0 -
Domain redirect
Recently we launched a site under a new domain, the site is doing well under the URL. Client calls me today and would like to have another domain he owns point to the new site. The domain he has has no history and no content. He is under the impression that people are looking for him by typing in www.domainxyz.com. I attempted to explain otherwise to him, but I lost. Question, what are the drawbacks of taking this domin and doing a perm redirect via . Httpaccess file?
Technical SEO | | VanadiumInteractive0 -
Redirect question
I would like to redirect http://example.com/index.html to http://www.example.com/ Is the code below correct ? RewriteEngine on RewriteCond %{HTTP_HOST}^example.comRewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/ RewriteRule ^index.html$ http://www.example.com/ [R=301,L]
Technical SEO | | seoug_20050 -
301 Redirect Question
I'm working on a site that has a lot of indexed pages and backlinks to both domain.com and www.domain.com. Will using a 301 redirect to send domain.com to www.domain.com merge all of the indexed pages and links over to www.domain.com, thereby strengthening the www?
Technical SEO | | Yo_Adrian0