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 related topics
I know that in order to rank on any keyword I need to talk about different "concepts / topics " everyone has a different word for it but let say I need to talk about multiple subject to make it simple. My question is how to find those subjects ... in some industry it is pretty straight forward you go to related search or some keyword tool such as Moz and you find what you need. Example : If "Title tag" is my main topic the subtopic that I find and that I need to cover on the same page are "title tag length , title tag checker, mobile title tag, title tag example etc..." On my keywords such as " Alsace bike tours" all I find in related searches and using all the tools out there such as Moz keyword research explorer is "Alsace cycling vacations " ""Cycling Colmar" "Alsace bike trip " etc... not really anything exiting , it means the same thing and it is just variations of the keyword. I have used other tools such as Marketmuse and they give me related topic such as "Strasbourg" "Colmar" "half timbered houses" "Alsace wine" and I am not sure it is any better... because to cover those I have no other solution that doing definitions... or describe those in details which is probably not what someone typing "Alsace bike tour" is looking for. I have the feeling that all those tools are great for keywords like "content marketing" or "title tag" with a lot of requests but they fail for everything else. Can someone give me an insight on how they do to write on multiple topic where they are in my situation and based on the example I gave which topic they would cover and based on my example.. Thank you,
Intermediate & Advanced SEO | | seoanalytics1 -
Temporary Blog Removal Process Question
Hello, We need to temporarily remove our entire blog from one of our sites. They rely very heavily on the blog content; as the rest of the site does not have much. Is there a 'best' process for going about this? – Should we put a 302 redirect on the entire blog and if so should it be to the homepage or an under-construction type page? Any extra insight or suggestions would be helpful and appreciated. Looking forward to hearing from you! Thank you in advance for the help. Best,
Intermediate & Advanced SEO | | Ben-R0 -
301 process, migration to new domain
Hi all! We have an old site wordpress based, with great ranking and PR 7, called www.europe-internship.com which is going to be migrated into our new Django site www.eurasmus.com (specifically eurasmus.com/en/europe-internships)
Intermediate & Advanced SEO | | Eurasmus.com
The new one is a much more advanced version that we will keep developing. We have been migrating the information already but we are planning to apply the 301s in the next weeks to start passing the SEO value to our new site and traffic. We have all the url structures and everything checked and technically we are ready for it.
Therefore, we are almost ready. I have 2 questions: The new site includes more services, like accommodation, information...not only internships. Therefore, should we point the most relevant urls from our previous site to our home to share the value or just to the internships section? I am afraid that if the bounce rate goes higher from the 301 we could loose some value... 2)Should we point all the urls at the same time to the new site? Home, vacancies, blog pages, etc... or start gradually doing it to see how it goes till we make it to all the pages including the home? The old site still makes some money and I am not sure how quick will be to pass the SEO value, so in the way we may loose few thousand euros...We understand that, but we want to check what would be the best in your opinion. Let me know what you think and your opinion! Thank you in advance!0 -
Metatags on drupal question
Hi Im quite inexperienced on drupal (normally an umbraco user!) and im having some difficulty with the Metatags on the CMS. I have been applying Meta Title and descriptions to the individual pages however they only appear when i preview the page and not when the page is saved. When i go into the metatag section located at /admin/config/search/metatags i am given a list of settings including Global: Front Page and Node. Im sure the reason it keeps defaulting the metatags back is to do with this but im not sure what to change to apply my own Thanks in advance
Intermediate & Advanced SEO | | TheZenAgency1 -
Robots.txt Question
For our company website faithology.com we are attempting to block out any urls that contain a ? mark to keep google from seeing some pages as duplicates. Our robots.txt is as follows: User-Agent: * Disallow: /*? User-agent: rogerbot Disallow: /community/ Is the above correct? We are wanting them to not crawl any url with a "?" inside, however we don't want to harm ourselves in seo. Thanks for your help!
Intermediate & Advanced SEO | | BMPIRE0 -
Undo a 301 redirect
Hi there, 4 months ago I have done a redirect from one domain to another. Now, after about 120 days I have just a few results from the old domain indexed. The problem is that I believe that the old domain name had a really big impact on rankings, as it had the main keyword in the domain name. I'm wondering now if I could restore the old domain just by taking out the 301 instruction and how will search engines react. Do you have any studies on that? Would it be possible? Matt Cutts himself did it with his own domain, but he doesn't talk specifically on the effect of the rankings: http://www.thedotcomblog.com/seo/redirects-after-change-in-domain-name Thanks in advance for any help,
Intermediate & Advanced SEO | | SandraMoZ0 -
Duplicate Content Question
My understanding of duplicate content is that if two pages are identical, Google selects one for it's results... I have a client that is literally sharing content real-time with a partner...the page content is identical for both sites, and if you update one page, teh otehr is updated automatically. Obviously this is a clear cut case for canonical link tags, but I'm cuious about something: Both sites seem to show up in search results but for different keywords...I would think one domain would simply win out over the other, but Google seems to show both sites in results. Any idea why? Also, could this duplicate content issue be hurting visibility for both sites? In other words, can I expect a boost in rankings with the canonical tags in place? Or will rankings remain the same?
Intermediate & Advanced SEO | | AmyLB0 -
Duplicate content even with 301 redirects
I know this isn't a developer forum but I figure someone will know the answer to this. My site is http://www.stadriemblems.com and I have a 301 redirect in my .htaccess file to redirect all non-www to www and it works great. But SEOmoz seems to think this doesn't apply to my blog, which is located at http://www.stadriemblems.com/blog It doesn't seem to make sense that I'd need to place code in every .htaccess file of every sub-folder. If I do, what code can I use? The weirdest part about this is that the redirecting works just fine; it's just SEOmoz's crawler that doesn't seem to be with the program here. Does this happen to you?
Intermediate & Advanced SEO | | UnderRugSwept0