Htaccess 301 regex question
-
I need some help with a regex for htaccess. I want to 301 redirect this:
to this:
changes:
- different protocol (http -> https)
- add 'www.'
- different domain (olddomain and newdomain are constants)
- different subdirectory (oldsubdir and newsubdir are constants)
- 'fruit' is a variable (which will contain only letters [a-zA-Z])
- is it possible to make 'fruit' UPPER case on the redirect (so 'fruit' -> 'FRUIT')
- remove '.aspx'
I think it's something like this (placed in the .htaccess file in the root directory of olddomain):
RedirectMatch 301 /oldsubdir/(.*).aspx https://www.newdomain.com/newsubdir/$1
Thanks.
-
Hi Mike,
I am happy it worked out.
you can use this to check as well
http://seo-website-designer.com/Response-Redirect-Header-Checker
All the best,
Tom
-
Hey Tom,
I guess this was mostly a regex question. I think I figured it out:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^oldsubdir/([a-zA-Z.]+).aspx$ https://www.newdomain.com/newsubdir/$1 [R=301]Thanks for the tips.
-
I would use http://www.htaccessredirect.net/
this can help to
http://www.webconfs.com/how-to-redirect-a-webpage.php
Let me know if you need anything
-
Thanks, Tom. But 'fruit' was a placeholder for a variable page name that can contain letters or a '.' (sorry if that wasn't clear). for example, 'fruit' could be "abc.def.aspx" and I'd like it to become "ABC.DEF" (strip off the .aspx and uppercase it). Need a regex. The '.' within 'fruit' may or may not be present. But the page will always have the suffix '.aspx' that I want to strip off.
I'd also like to do it with an .htaccess statement instead of VBScript. Running on unix.
-
You would use
<%@ Language="VBScript" %>
<%
' ASP permanent URL redirect - generated by www.rapidtables.com
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "https://www.newdomain.com/newsubdir/FRUIT"
Response.End
%>try
http://www.rapidtables.com/web/tools/redirect-generator.htm
I hope this helps,
Tom
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
-
Question About Permalink Showing Up in Search Results
Does Google determine how your permalink shows up in the search results or is that a setting on our end? I noticed most of our competitors have their permalink show up in their snippet results. Ours shows "knowledgebase" instead. I think seeing the keywords in the permalink helps with conversions. https://screencast.com/t/fyFyNaWayajx
Intermediate & Advanced SEO | | LindsayE0 -
Duplicate Content Question With New Domain
Hey Everyone, I hope your day is going well. I have a question regarding duplicate content. Let's say that we have Website A and Website B. Website A is a directory for multiple stores & brands. Website B is a new domain that will satisfy the delivery niche for these multiple stores & brands (where they can click on a "Delivery" anchor on Website A and it'll redirect them to Website B). We want Website B to rank organically when someone types in " <brand>delivery" in Google. Website B has NOT been created yet. The Issue Website B has to be a separate domain than Website A (no getting around this). Website B will also pull all of the content from Website A (menus, reviews, about, etc). Will we face any duplicate content issues on either Website A or Website B in the future? Should we rel=canonical to the main website even though we want Website B to rank organically?</brand>
Intermediate & Advanced SEO | | imjonny0 -
301 redirect to multiple domain
Hi guys, I have a domain A, B and C. The domain A was an association of two business and they are about to split. Parts of domain A are going to be redirect to domain B, but some content belong to the domain C. So my question : Is it possible to 301 redirect some pages from A to B and some other pages from A to C and if yes, what would be the impact on SEO ? Thanks a lot!
Intermediate & Advanced SEO | | StevePatenaude0 -
Removing Content 301 vs 410 question
Hello, I was hoping to get the SEOmoz community’s advice on how to remove content most effectively from a large website. I just read a very thought-provoking thread in which Dr. Pete and Kerry22 answered a question about how to cut content in order to recover from Panda. (http://www.seomoz.org/q/panda-recovery-what-is-the-best-way-to-shrink-your-index-and-make-google-aware). Kerry22 mentioned a process in which 410s would be totally visible to googlebot so that it would easily recognize the removal of content. The conversation implied that it is not just important to remove the content, but also to give google the ability to recrawl that content to indeed confirm the content was removed (as opposed to just recrawling the site and not finding the content anywhere). This really made lots of sense to me and also struck a personal chord… Our website was hit by a later Panda refresh back in March 2012, and ever since then we have been aggressive about cutting content and doing what we can to improve user experience. When we cut pages, though, we used a different approach, doing all of the below steps:
Intermediate & Advanced SEO | | Eric_R
1. We cut the pages
2. We set up permanent 301 redirects for all of them immediately.
3. And at the same time, we would always remove from our site all links pointing to these pages (to make sure users didn’t stumble upon the removed pages. When we cut the content pages, we would either delete them or unpublish them, causing them to 404 or 401, but this is probably a moot point since we gave them 301 redirects every time anyway. We thought we could signal to Google that we removed the content while avoiding generating lots of errors that way… I see that this is basically the exact opposite of Dr. Pete's advice and opposite what Kerry22 used in order to get a recovery, and meanwhile here we are still trying to help our site recover. We've been feeling that our site should no longer be under the shadow of Panda. So here is what I'm wondering, and I'd be very appreciative of advice or answers for the following questions: 1. Is it possible that Google still thinks we have this content on our site, and we continue to suffer from Panda because of this?
Could there be a residual taint caused by the way we removed it, or is it all water under the bridge at this point because Google would have figured out we removed it (albeit not in a preferred way)? 2. If there’s a possibility our former cutting process has caused lasting issues and affected how Google sees us, what can we do now (if anything) to correct the damage we did? Thank you in advance for your help,
Eric1 -
Multiple 301 Redirects for the Same Page
Hi Mozzers, What happens if I have a trail of 301 redirects for the same page? For example,
Intermediate & Advanced SEO | | Travis-W
SiteA.com/10 --> SiteA.com/11 --> SiteA.com/13 --> SiteA.com/14 I know I lose a little bit of link juice by 301 redirecting.
The question is, would the link juice look like this for the example above? 100% --> 90% --> 81% -->72.9%
Or just 100% -----------------------------------------> 90% Does this link juice refer to juice from inbound links or links between internal pages on my site? Thanks!0 -
Setting Up Google Analytics for domains with 301
I have a client with a google analytics account that is a mess. domaina.com domainb.com 302's to domaina.com domainc.com 302's to domaina.com domaind.com 302's to domaina.com I thought the client was doing 301s on all these domains to the primary domain. I have logged into there analytics account and found data is being tracked on the other domains i.e domainb,c,d.com etc. How is it possible that google analytics is tracking data on these domains when no analytics code has been created and the urls are redirecting to domaina.com? Also there are not sites on these domains so for webmaster tools should I enable domain verification through a cname on the dns? Also I can I best setup a way to track traffic coming from say domainb.com? Whats the best step by step guide to use to set this up.
Intermediate & Advanced SEO | | JohnW-UK0 -
Question about HTTP Vary for Mobile
I'm reviewing https://developers.google.com/webmasters/smartphone-sites/redirects, and wondering where exactly to add HTTP Vary: Desktop request which has a mobile page to add “Vary: User-Agent” to the response HEADER Or if the request came from mobile device, than add “Vary: User-Agent” to the response HEADER
Intermediate & Advanced SEO | | nicole.healthline0 -
Probelms w/ 301 Redirects
I am trying to 301 redirect my old site to the new site (under the same domain. Most of the 404 urls are 301 redirects from 404 pages but they are still able to redirect. I need help understanding why I cannot redirect half of my list. <colgroup><col width="636"> <col width="342"> <col width="64"></colgroup>
Intermediate & Advanced SEO | | Melia
| OLD URL | 301 To: | Status |
| http://www.meliacaribetropical.com/en/groups.html | http://www.meliacaribetropical.com/en/groups.html | done |
| http://www.meliacaribetropical.com/entertainment/ | http://www.meliacaribetropical.com/en/services.html | done |
| http://www.meliacaribetropical.com/es/all_inclusive.html | http://www.meliacaribetropical.com/es/index.html | done |
| http://www.meliacaribetropical.com/es/galeria/ | http://www.meliacaribetropical.com/es/visor.html | done |
| http://www.meliacaribetropical.com/es/los-picapiedra/ | http://www.meliacaribetropical.com/es/index.html | done |
| http://www.meliacaribetropical.com/es/outside-us-telephone-listing.php | http://www.meliacaribetropical.com/en/index.html | done |
| http://www.meliacaribetropical.com/es/restaurantes/ | http://www.meliacaribetropical.com/es/gastronomia.html | done |
| http://www.meliacaribetropical.com/es/reuniones-eventos/ | http://www.meliacaribetropical.com/es/grupos.html | done |
| http://www.meliacaribetropical.com/es/spa/ | http://www.meliacaribetropical.com/es/servicios.html | done |
| http://www.meliacaribetropical.com/es/terms-condition.php | http://www.meliacaribetropical.com/es/index.html | done |
| http://www.meliacaribetropical.com/gallery/beach.html | http://www.meliacaribetropical.com/en/index.html | done |
| http://www.meliacaribetropical.com/gallery/dining.html | http://www.meliacaribetropical.com/en/gastronomy.html | done |
| http://www.meliacaribetropical.com/gallery/pools.html | http://www.meliacaribetropical.com/en/index.html | done |
| http://www.meliacaribetropical.com/lowest-rate.php | http://www.meliacaribetropical.com/en/index.html | done |
| http://www.meliacaribetropical.com/press/ | http://www.meliacaribetropical.com/en/index.html | done |
| http://www.meliacaribetropical.com/spanish/ | http://www.meliacaribetropical.com/es/index.html | done |
| http://www.meliacaribetropical.com/spanish/services/ | http://www.meliacaribetropical.com/en/services.html | done |
| http://www.meliacaribetropical.com/spanish/services/ | http://www.meliacaribetropical.com/es/servicios.html | done |
| http://www.meliacaribetropical.com/terms-condition.php | http://www.meliacaribetropical.com/en/index.html | done |
| http://www.meliacaribetropical.com/es/galeria/piscinas.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/es/galeria/playa.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/es/galeria/restaurantes.html | http://www.meliacaribetropical.com/es/gastronomia.html |
|
| http://www.meliacaribetropical.com/es/prensa/ | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/es/prensa/family-facilities-amenities.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/es/prensa/melia-caribe-tropical-announces-fall-promotion.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/es/prensa/melia-international-brand-overhaul.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/press/family-facilities-amenities.html | http://www.meliacaribetropical.com/en/index.html |
|
| http://www.meliacaribetropical.com/press/melia-caribe-tropical-announces-fall-promotion.html | http://www.meliacaribetropical.com/en/index.html |
|
| http://www.meliacaribetropical.com/press/melia-international-brand-overhaul.html | http://www.meliacaribetropical.com/en/index.html |
|
| http://www.meliacaribetropical.com/spanish/accommodations/ | http://www.meliacaribetropical.com/es/habitaciones.html |
|
| http://www.meliacaribetropical.com/spanish/dining/ | http://www.meliacaribetropical.com/es/gastronomia.html |
|
| http://www.meliacaribetropical.com/spanish/entertainment/ | http://www.meliacaribetropical.com/es/servicios.html |
|
| http://www.meliacaribetropical.com/spanish/events/ | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/spanish/flintstones/ | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/spanish/gallery/ | http://www.meliacaribetropical.com/es/visor.html |
|
| http://www.meliacaribetropical.com/spanish/gallery/beach.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/spanish/gallery/dining.html | http://www.meliacaribetropical.com/es/gastronomia.html |
|
| http://www.meliacaribetropical.com/spanish/gallery/pools.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/spanish/press/ | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/spanish/press/melia-caribe-tropical-announces-fall-promotion.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/spanish/press/melia-international-brand-overhaul.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/spanish/royal/ | http://www.meliacaribetropical.com/es/servicio-real.html |
|
| http://www.meliacaribetropical.com/spanish/sitemap.html | http://www.meliacaribetropical.com/es/index.html |
|
| http://www.meliacaribetropical.com/spanish/spa/ | http://www.meliacaribetropical.com/es/servicios.html |
| gastronomia.html0