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
-
Unintentional wildcard 301 Redirect?
I have migrated a client's site to a new domain. I used Yoast tools to add 301 redirects for all active site pages from old domain to new domain in the .htacces files as neither the client nor I have access to hosting server via FTP (long story). Redirects are working as I intended, and we didn't lose too much in our rankings. Unfortunately, as soon as I saved the .htaccess file in Yoast, old-domain.net/wp-admin began redirecting to new-domain.net/wp-admin. I can no longer login to the wordpress site on the old domain. I did not enter a redirect for /wp-admin. Any thoughts on how this is happening or if there is some other way to get back in? Without server access, I'm pretty stumped. Thanks!
Intermediate & Advanced SEO | | c_estep_tcbguy0 -
Question about Syntax in Robots.txt
So if I want to block any URL from being indexed that contains a particular parameter what is the best way to put this in the robots.txt file? Currently I have-
Intermediate & Advanced SEO | | DRSearchEngOpt
Disallow: /attachment_id Where "attachment_id" is the parameter. Problem is I still see these URL's indexed and this has been in the robots now for over a month. I am wondering if I should just do Disallow: attachment_id or Disallow: attachment_id= but figured I would ask you guys first. Thanks!0 -
Question | Blogger, Godaddy, HostGator
If I buy a new domain and do forwarding with masking to my blogger post URL what would happen to the backlinks that were pointing to my blog post exactly? Will the power link back to this new domain or will it stay there? I have a blogger account, a domain from godaddy, and hosting? People are telling me that forwarding with masking is bad for <acronym title="Search Engine Optimization">SEO</acronym> so I should set blogger with godaddy or something like that I don't know. I need a hosting though in order to do that and free ones don't offer changes to the CNAME records? so I got hostgator. I am up to the part where I need to set the records in the CNAME for hostgator but every time I try to list ghs.google as the whatever, it won't work! It keeps telling me the record is already there when this is my FIRST time using this! How can it be there when I haven't even touched it? Please help me This is the tutorial im using : http://support.google.com/blogger/bi...381&page=ts.cs I get stuck here: Find the control panel on your domain registrar’s website, and locate your DNS (Domain Name System) settings. In order to link your blog to your custom domain, follow the instructions below to enter your "CNAME" and "A-records."
Intermediate & Advanced SEO | | 678648631264
CNAME
Where it says Name, simply enter "www" and list ghs.google.com as the Host Name. See our detailed instructions on providing CNAMEs for various registrars. If yours isn't listed, or if you run into other difficulties, contact your registrar directly and they can help you out.
A-records (optional)
The following action links your naked domain (example.com) to your actual site (www.example.com). If you skip this step, visitors who leave off the "www" will see an error page.
Enter your domain name in the format example.com, and list the I.P. addresses shown below in the "A" section. You'll need to create four separate A-records which point to four different Google IPs. 216.239.32.21
216.239.34.21
216.239.36.21
216.239.38.21 Could I just leave my forwarding with masking on with my domain + blogger to make everything easier or what? And, is there any benefit in SEO if I don't have an EMD but it's something like this www.General.com/Keyword 1 www.General.com/Keyword 2/Posts/etc0 -
Spammy Link Profile Questions. What do you think?
I'm trying to dilute the link profile for a website. But have a couple of questions on the best way to achieve this. Current link profile, www.mysitename.com Keyword 1 Keyword 2 Keyword 3 Keyword 4 Keyword 5 Keyword 6 Keyword 7 Keyword 8 Keyword 9 Keyword 10 Keyword 12 Keyword 13 Keyword 14 Keyword 14 Keyword 15 mysitename.com Desired link profile, www.mysitename.com mysitename.com www.mysitename.com http://www. mysitename.com/ My Site Name http://mysitename.com Click Here my site name More Info mysitename.com/ www.mysitename.com/ Keyword 1 Keyword 2 Keyword 3 Keyword 4 Keyword 4 Keyword 5 Questions 1. Do you think Google looks at this on a domain level? Or do you think this needs to be done with every page on the site? 2. What would be a good way to build links fast to the pages, need to build lots of links to be able to dilute the profile. I was considering Dripable, or a similar service, but decided i really don't want to create more spam.What would you do? 3. What would you say the % threshold for anchor text is, i have read on different sources that at least 40% - 60% of links should be branded, url, or generic anchor links. Do you think this is accurate?
Intermediate & Advanced SEO | | 858-SEO0 -
Apache Mod Rewrite question
Hi everybody, I need to rewrite this url using mod rewrite, but I've got stuck. http://www.diamondgeezer.com/theultimate/search/index.php?sortprice=asc&followSearch=9673&q=eternity+rings I'd like it to show this one instead: http://www.diamondgeezer.com/eternity-rings I'm no expert on this stuff, so any help would be great! Thanks
Intermediate & Advanced SEO | | neooptic0 -
$1,500 question
I have $1,500 to spend to promote 8 years old website. Almost no SEO work was done for the site in the past 3-4 years. The site has a couple hundreds (around 300) external backlinks pointing to the homepage, and around 30 backlinks pointing to internal pages. It gets around 60% traffic from referring sites, 30% direct, and 10% from SE. The homepage has PR 4. It ranks around 70th place in Google rankings for one of the main keywords. No keyword research has been done for the site. Looking for long term benefits. What would be the best way, in your opinion, to spend this money?
Intermediate & Advanced SEO | | _Z_0 -
Canonical tag question
Suppose a site has two pages ( Page A ) and Page B. Both of them have pagerank, but duplicate content. The page A is ranked for keyword "seo india" and page B is ranked for keyword "seo services". If i implement canonical tag on page B, does 1. The pagerank of page B will be transfered to Page A ? 2. Does the site A now ranks for keyword "seo servicies " ( for which Page B was ranking earlier )
Intermediate & Advanced SEO | | seoug_20050 -
Advanced Question on Synonym Variation Pages!
Hi, This is quite an advanced question, so I'll go through in detail - please bare with me! I launched the new version of our website exactly a week ago - and all the key metrics are in the right direction: Pages / Visit +5% , Time on Site +25%, Bounce rate down 1 %. I work in an industry were our primary keyword has 4 synonyms and our long tail keywords are location related. So as an example I have primary synonyms like: Holiday, Vacation, Break, Trip (Not actually these but they are good enough as an example). Pluralised versions and you have 8 in total. So my longtail keywords are like: Las Vegas Vacation / Las Vegas Vacations
Intermediate & Advanced SEO | | James77
Las Vegas Holiday / Las Vegas Holidays
Las Vegas Trip / Las Vegas Trips
Las Vegas Breaks / Las vegas Breaks All these synonyms effectively mean the same thing, so my thinking on my new website was to specifically target each of these synonyms with their own unique page and optimise the meta and page titles, to those exact words. To make these pages truely unique, I therefore got a bunch of copywriters to write about 600 words unique for every long tail synonym (well over 750,000 words in total!). So now at this point I have my page "Las Vegas Holidays" with 600 unique words of content, and "Las Vegas Vactions" with 600 words of unique content etc etc etc. The problem is, when the user is searching for these words, there primary goal is not to read 600 words of content on "Las Vegas Holidays" - their primary goal is to get a list of last vegas holidays that they can search, view purchase (they may want to read 600 words of content, but is not their primary goal). So this puts me in a dilema - I need to display the nuts and bolt (IE the actual holidays in las vegas) to the customer on any page they land on off my synonyms as the primary content. But to make sure these pages are unique I need to also have this unique content on that page. So here's what I did: On every synonym version of the page I display the exact same information. However, on each page I have a "Information" link. and on click this pop's up a layer which contains my unique content for that page. To further optimise using perfect anchors in this content pop-up, I have cross linked the synonym pages (totally naturally) - IE on my "Las Vegas Holidays" page, in the content I may have the words "Las Vegas Breaks" - this would be linked the the "Las Vegas Breaks" synonym page. In theory I don't think there is anything wrong with what I am doing in the eyes of the customer - but I have a big concern that this may well look "fishy" to SE's. IE the pages are almost identical to the user except for this information pop-up layer of unique content, titles and meta. We know that Google at least can get can tell exactly what the user see's when they land on that page ( from their "Preview") and can distinguise between user visible and hidden text. Therefore, even though from a user experience, I think we are making a page that is perfect for them (they get the list of vactions etc as the primary content, and can read infomation if they want by clicking a button), I am concerned that SE's are going to say - hold on a minute there are load of pages here that are identical except for a chuck of text that is not visible to the user (Even though this is visible to the user if they click the "Information" button), and this content cross links to a load of almost identical pages with the same thing. Today I checked our rankings, and we have taken a fair whack from google - I'm not overly concerned at the moment as I expected big fluctuations from ranking for the first few weeks - but I'd be a lot more confident if they were fluctuating in the right direction!! So what do I do?
As far as I can see my options break down as follows: Content Display:
1/. Keep it as it is, and hope the SE's don't see it as spammy. Even though I think what we are doing is the best for customer experience, I'm concerned SE's won't. 2/. On every synonym page, below all the list of products, packages etc that the customer wants to see, display the unique content as a block of subtext text which is visble by default. This however could make the page a bit ugly. 3/. Display a visible snippet of the unique content, below all the packages, and have a more button which expands the rest of the content - IE have a part visible layer. This is slightly better for display, but again I'm only displaying a portion of visible content and the rest will still be flagged as "hidden" by default to the SE's. Cross Linking within the content:
1/. Keep it as it is where synonym keywords link to the synonym version of the page. 2/. Alter it so that every sysnonym keyword links to the "primary" synonym version of the page - EG if I now "Las Vegas Holidays" is my main keyword, then "Las Vegas Vactions" keyword, would not link to my "Las Vegas Vactions" page as current, but would link to my "Las Vegas Holidays" page. I apologise for the indepth questions, but it requires a lot of explanation to get it across clearly. I would be grateful on any of your thoughts. Many thanks in advance.0