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 region codes and Hreflang?
A client (see example above) has accidentally place region codes into the hreflang when the content is intended for all audiences that speak the language. So "fr-fr" should really just be "fr" since those that are "fr-be", "fr-ca", and "fr-ch" should all be getting to the French version of the website too. And there isn't a specific subdirectory for French speakers in Belgium or France or Switzerland, etc. However, when looking at Google Analytics, these region codes don't seem to be stopping those from other regions from getting to the correct landing page. So a user from Belgium is still getting to https://www.example.com/fr/ depsite the "fr-fr" in the hreflang. So question: is it worth adjusting the hreflang to be non-region specific (from
Intermediate & Advanced SEO | | SearchStan0 -
Question about Indexing of /?limit=all
Hi, i've got your SEO Suite Ultimate installed on my site (www.customlogocases.com). I've got a relatively new magento site (around 1 year). We have recently been doing some pr/seo for the category pages, for example /custom-ipad-cases/ But when I search on google, it seems that google has indexed the /custom-ipad-cases/?limit=all This /?limit=all page is one without any links, and only has a PA of 1. Whereas the standard /custom-ipad-cases/ without the /? query has a much higher pa of 20, and a couple of links pointing towards it. So therefore I would want this particular page to be the one that google indexes. And along the same logic, this page really should be able to achieve higher rankings than the /?limit=all page. Is my thinking here correct? Should I disallow all the /? now, even though these are the ones that are indexed, and the others currently are not. I'd be happy to take the hit while it figures it out, because the higher PA pages are what I ultimately am getting links to... Thoughts?
Intermediate & Advanced SEO | | RobAus0 -
Technical 301 question
Howdy all, this has been bugging me for a while and I wanted to know the communities ideas on this. We have a .com website which has a little domain authority and is growing steadily. We are a UK business (but have a US office which we will be adapting too soon) We are ranking better within google.com than we do on google.co.uk probably down to our TLD. Is it a wise idea to 301 our .com to .co.uk for en-gb enquiries only? Is there any evidence that this will help improve our position? will all the link juice passed from 301s go to our .co.uk only if we are still applying the use of .com in the US? Many thanks and hope this isn't too complicated! Best wishes,
Intermediate & Advanced SEO | | TVFurniture
Chris0 -
Specific KW question...
Hi, I have this site: http://www.aerlawgroup.com. It's ranking very well overall for all targeted KWs. However, I have seen a drop for one main KW: "Los Angeles criminal defense attorney." It currently ranks #8 (it used to be as high as #2). What's interesting is that for similar (yet slightly less competitive KWs, he ranks much better - "Los Angeles Criminal Defense Lawyer." I'm not trying to be greedy with rankings, but I would love feedback and/or tips regarding any issues that could be contributing to this drop. Thanks.
Intermediate & Advanced SEO | | mrodriguez14400 -
301 redirects and Blogger - moving blog
Is there any way to add 301 redirects to individual posts on a blogger-hosted blog? We're getting ready to finally move our blog off of Blogger and onto our own webserver. We're probably going to use BlogEngine.net to run it. right now the blog is located at blog.MySite.com. We're probably going to move it to MySite.com/Blog. We don't have any really popular posts and we only really get ~10 visits a day on about 70 posts. Just trying to figure out the best way to handle this without inadvertently shooting myself in the foot.
Intermediate & Advanced SEO | | _JP_0 -
My site penalized after 301 Redirect or redesign?
Hi, I have a question regarding my site (http://www.pokeronlineitalia.com) that has, all of a sudden, lost rankings on several keywords; plus, Google Analytics and the plug-in Clicky installed on my site (the site is built on WordPress) claim that my site has no visitors/visits anymore. I would like to provide a little background of what has happened. Three weeks ago I asked my web hosting company to do a 301 redirect from http://pokeronlineitalia.com to http://www.pokeronlineitalia.com. At the same time I asked a web hosting company to to a redesign of the site. Strangely, the day after the new redesigned site went online Google Analytics and the Clicky plug-in showed that my site, from one day to the other, had no visitors/visits anymore (I had installed Google Analytics and Clicky before the 301 redirect). In addition, I noticed that I had lost positions on many keywords for which I used to rank on the second page. However, the PR of the site has remained intact and Google is indexing it without problems. Plus, I still rank high for a keyword. I tend to believe that because of this, my site was not penalized by mighty Google...but I'd like an SEO expert to tell me what he thinks about it. In particular, please answer this: has my site lost rankings because of the 301 redirect? Has my site been penalized because of the redesign? Is this only a temporary situation? Thank you very much for your help. Sal
Intermediate & Advanced SEO | | salvyy0 -
Unique Ip Hosting Question
We have aged domains that have had unique ips for some time. Batch 1 average 2 years old and are in 1st to 5th place in their rankings. Batch 2 are 8 months old and not ranking at all. Will there be any issues associated with moving them all to a reseller account with a single ip address? In addition batch 1 that has good rankings with unique ips is there ever a possibility they will change our ips without notice or for any reason at all that will change and or fluctuate our rankings?
Intermediate & Advanced SEO | | shandaman0 -
SEO question
Hi i changed my page titles for a competitive keyword last week and noticed it has dropped 9 search engine ranking positions. Was ranking 37 and now it 46. Would you guys leave it and see if it starts creeping back up or change again? the page title i used was across my pages for example was Primary keyword | secondary keyword | Heading on page thanks for you help
Intermediate & Advanced SEO | | wazza19850