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
-
How to remove 302 redirects in Magento?
We're seeing a couple of temporary redirects. One for the http pointing to https. Another for /checkout pointing to/checkout/cart. We don't have an internal dev so not sure how to remove these. Would anyone know? I've set up the 301s but they're not overriding and I'm still seeing the issues in the crawl. Thanks in advance for your help!
Technical SEO | | LASClients0 -
Javascript is redirecting search bots to mobile
Here is the javascript I am using to send users to the mobile version of my website: This is causing major issues in Bing and Yahoo as the mobile website is the only thing ranking. I'd love any help dissecting this issue. Thanks in advance.
Technical SEO | | ShawnW0 -
Redirecting a Few URLS from One Domain to Another
Hello, I have two websites within a similar niche...some of the top organic traffic driving pages on Website B I'd like to redirect to a similar page on Website A. The reason is Website A is a bigger and better and is monetized much better as well. I only want to redirect a few of the main URLS on Website A and also only those that I have similar content on my main Website B. Is this process safe for SEO? What is the best way to go about this process. I am not really concerned with Website B and what happens to it's rankings, but in the meantime, I'd like to redirect the traffic from some of it's main organic traffic driving pages to my main website A and to it's similar pages. I am also concerned with making sure my main website A stays white hat and doesn't receive any negativity from these redirects. Thanks.
Technical SEO | | juicyresults0 -
301 Redirect domain with penalty
Wondering if I could get a few views on this please... I have added an affiliate store to a domain I own, however I forgot to noindex the product pages which were duplicate content of the merchants. Despite a good deal of backlink building the site will not do much in the engines at all, doesn't even come up on the first few pages for it's own name! This suggests to me that I have a duplicate content penalty. Try as I may I cannot get it removed so am thinking of cloning the domain to a new domain, however, I do not want to lose the links I collected so I am planning on 301ing them. While I will not get all the link power moved over, I should at least get credit for some of them which will kick start the new domain. Can anyone forsee any potential issues with doing this? Is there a danger of 301ing a site with a penalty that the penalty would be carried over? I know there is no penalty on the links, no WMT warnings etc, it is the content causing the issue. Thanks, Carl
Technical SEO | | Grumpy_Carl0 -
301 redirect issues
Hi all, I'm hoping someone will be able to help me with an extermley frustrating problem with 301 redirects in .htaccess. Basically I'm trying to redirect some old pages (from our old website) that stil rank to the new equivilent. For example - old url = www.domain.com/frames/news/company-news/news-reader.php?newsStoryID=395 New www.domain.com/news/article-title I've tried the simple redirect 301 /frames/news/company-news/news-reader.php?newsStoryID=395 http://www.domain.com/news/article-title But this doesnt work. I've also tried - RewriteEngine on
Technical SEO | | EclipseLegal
RewriteCond %{QUERY_STRING} ^newsStoryID=395$
RewriteRule ^/news-reader.php$ http://www.domain.com/news/article-title/? [L,R=301] Could anyone help? I've followed lots of tutorials that all match the above but it just doesn't work! The only other thing within the htaccess file is from wordpress for pretty permalinks - BEGIN WordPress <ifmodule mod_rewrite.c="">RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]</ifmodule> END WordPress Many thanks in advance!0 -
Redirects
Hello, My question is: how important is it to wait for the a redirect to get seen and cached before you take down the old page? More in depth: my old platform has seriously limited my ability to add sitemaps and make edits to htacces. I just want to change nameservers (which will delete everything on there) and upload the htaccess is that alright? Another way of saying it: when redirecting a page, is it necessary for google to see the old page before it is deleted? Thanks Tyler
Technical SEO | | tylerfraser0 -
Redirecting root domains to sub domains
Mozzers: We have a instance where a client is looking to 301 a www.example.com to www.example.com/shop I know of several issues with this but wondered if anyone could chip in with any previous experiences of doing so, and what outcomes positive and negative came out of this. Issues I'm aware of: The root domain URL is the most linked page, a HTTP 301 redirect only passes about 90% of the value. you'll loose 10-15% of your link value of these links. navigational queries (i.e.: the "domain part" of "domain.tld") are less likely to produce google site-links less deep-crawling: google crawls top down - starts with the most linked page, which will most likely be your domain url. as this does not exist you waste this zero level of crawling depth. robots.txt is only allowed on the root of the domain. Your help as always is greatly appreciated. Sean
Technical SEO | | Yozzer0 -
301 Redirect NOT Working as Expected - HELP!
Hi! I just launched our newly coded site and just realized the installed 301 is NOT working. The URL string is the same EXCEPT for the removal of /shop/. Here is the code in .htaccess: ############################################ enable rewrites Options +FollowSymLinks RewriteEngine on #RedirectMatch 301 ^/shop?/$ http://hiphound.com/ RedirectMatch 301 ^/shop?/$ http://hiphound.com ########################################### When I go to Google and click on an old link I get a 404. No bueno!! Here is an example: http://hiphound.com/shop/rubit-dog-tag-clip I thought (and was told) that the installed 301 would send this page to: http://hiphound.com/rubit-dog-tag-clip It's not. Please HELP!! 🙂 What am I doing wrong??? Lynn
Technical SEO | | hiphound0