Moz Q&A is closed.
After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.
301 redirect syntax for htaccess
-
I'm working on some htaccess redirects for a few stray pages and have come across a few different varieties of 301s that are confusing me a bit....Most sources suggest:
Redirect 301 /pageA.html http://www.site.com/pageB.html
or using some combination of:
RewriteRule + RewriteCond + RegEx
I've also found examples of:
RedirectPermanent /pageA.html http://www.site.com/pageB.html
I'm confused because our current htaccess file has quite a few (working) redirects that look like this:
Redirect permanent /pageA.html http://www.site.com/pageB.html
This syntax seems to work, but I'm yet to find another Redirect permanent in the wild, only examples of Redirect 301 or RedirectPermanent
Is there any difference between these? Would I benefit at all from replacing Redirect permanent with Redirect 301?
-
There is no difference between "Redirect 301", "Redirect permanent" and "RedirectPermanent". It is clear from mod Alias documentation:
"This directive makes the client know that the Redirect is permanent (status 301). Exactly equivalent to
Redirect permanent
." "permanent - Returns a permanent redirect status (301) indicating that the resource has moved permanently."But, these directives are really confusing, because they are not page to page, but directory to directory. For example:
Redirect 301 /a-very-old-post/ http://yoursite.com/a-very-new-post/
Surprisingly, it will redirect all old subpages to new subpages. In particular it will redirect /a-very-old-post/page1 to /a-very-new-post/page1 Therefore better to use RedirectMatch or RewriteCond+RewriteRule for page by page redirections and for redirections with query strings.
Links to docs: https://docs.oracle.com/cd/B14099_19/web.1012/q20206/mod/mod_alias.html
Link to simple RedirectMatch page by page redirects generator: RedirectMatch generator for htaccess https://www.301-redirect.online/htaccess-redirectmatch-generator
Link to good RewriteRule generator: htaccess 301 redirect rewrite generator https://www.301-redirect.online/htaccess-rewrite-generator
-
In **apache **"permanent" "RedirectPermanent" is the same as "Redirect 301"
By default, the "Redirect" directive establishes a 302, or temporary, redirect.
If you would like to create a permanent redirect, you can do so in either of the following two ways:
- Redirect 301 /oldlocation http://www.domain2.com/newlocation
- Redirect permanent /oldlocation http://www.domain2.com/newlocation
Page to Page 301 Redirect Generator for Htaccess
https://www.aleydasolis.com/htaccess-redirects-generator/
If no <var>status</var> argument is given, the redirect will be "temporary" (HTTP status 302). This indicates to the client that the resource has moved temporarily. The <var>status</var> argument can be used to return other HTTP status codes:
<dl> "permanent" & "Redirect 301"</dl>
<dl>
<dd>Returns a permanent redirect status (301) indicating that the resource has moved permanently.</dd>
"temp"</dl>
<dl>
<dt>Returns a temporary redirect status (302). This is the default.</dt>
"seeother"</dl>
<dl>
<dd>Returns a "See Other" status (303) indicating that the resource has been replaced.</dd>
"gone"</dl>
<dl>
<dd>Returns a "Gone" status (410) indicating that the resource has been permanently removed. When this status is used the <var>URL</var> argument should be omitted.</dd>
</dl>
**https://httpd.apache.org/docs/2.4/mod/mod_alias.html **
https://www.bruceclay.com/blog/how-to-properly-implement-a-301-redirect/
To 301 Redirect a Page:
RedirectPermanent /old-file.html http://www.domain.com/new-file.html
To 301 Redirect a Page:
Redirect 301 /old-file.html http://www.domain.com/new-file.html
https://i.imgur.com/PTEj5ZF.png
https://www.aleydasolis.com/htaccess-redirects-generator/
Single URL redirect
Permanent redirect from pageA_.html_ to pageB.html.
.htaccess:
301 Redirect URLs.
Redirect 301 /pageA.html http://www.site.com/pageB.html
https://www.aleydasolis.com/htaccess-redirects-generator/page-to-page/
<ifmodule mod_rewrite.c="">RewriteEngine On
Redirect 301 /pageA.html /pageB.html</ifmodule>https://www.htaccessredirect.net/
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site.com[nc]
RewriteRule ^(.*)$ http://www.site.com/$1 [r=301,nc]//301 Redirect Old File
Redirect 301 /pageA.html /pageB.htmlYou asked about Regex
https://mediatemple.net/community/products/dv/204643270/using-htaccess-rewrite-rules
.htaccess
Regular expressions
Rewrite rules often contain symbols that make a regular expression (regex). This is how the server knows exactly how you want your URL changed. However, regular expressions can be tricky to decipher at first glance. Here's some common elements you will see in your rewrite rules, along with some specific examples.
- ^ begins the line to match.
- $ ends the line to match.
- So, ^folder1$ matches folder1 exactly.
- . stands for "any non-whitespace character" (example: a, B, 3).
- * means that the previous character can be matched zero or more times.
- So, ^uploads.*$ matches uploads2009, uploads2010, etc.
- ^.*$ means "match anything and everything." This is useful if you don't know what your users might type for the URL.
- () designates which portion to preserve for use again in the $1 variable in the second string. This is useful for handling requests for particular files that should be the same in the old and new versions of the URL.
See for more regex
- http://perldoc.perl.org/perlre.html#Regular-Expressions
- https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/
- https://www.askapache.com/htaccess/
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
-
What is the difference between 301 redirects and backlinks?
i have seen some 301 redirects on my site billsonline, can anyone please explain the difference between backlinks and 301 redirects, i have read some articles where the writer was stating that 301 are not good for website.
Technical SEO | | aliho0 -
How do you fix redirect chains and temporary redirects?
Hi, I have a lot of issues popping up with temporary redirects and redirect chains. I'm still confused as to what exactly redirect chains are and I don't know how to find where the "chains" are or how to fix them. I'm having two issues mainly:1. Temporary RedirectsI have around 100 pages on our www.twowayradiosfor.com website that are being flagged as temporary redirects. All of them have one thing in common: they are review pages (basically, when a customer clicks on the Review button to review a certain product, they are redirected to a review page for that product).URL Example: https://www.twowayradiosfor.com/reviewhelpful.asp?ProductCode=CLS1410-COMBO&ID=44&yes=noI went into our website and set any URL containing the following as noindex:/review.aspWill that fix the issue? If yes, will I also need to do that for any URL containing /reviewhelpful.asp?2. Redirect ChainsIt seems like basically every product page on my website has this issue (over 100 pages). Here's an example of one:https://www.twowayradiosfor.com/Motorola-CLS1110-p/cls1110.htmI don't see any broken links on this page or links that redirect to another page that redirects, etc. What is causing this? Is it something on my header bar that is redirecting (since that header bar appears on every page, maybe that is why this issue shows up on a lot of pages)?I am new to Moz and still trying to figure this stuff out. I really appreciate any help. Thanks, Sawyer
Technical SEO | | AllChargedUp0 -
301 with nofollow ?
Hi, our ecommerce link penalty was revoked by google back in Feb 26th 2013, but to this day we have not seen any improvement on our rankings. Due to 80% revenue loss we had to layoff quite a few people to stay alive. Situation now is more dire then ever for our company. We have millions of dollars invested in our business and google just busted it for some "low quality" or "spammy links" as they call it. We want to try to move to a different domain and do a 301 from the old domain to make sure our previous customers can still find us as a last effort to stay alive. But doing so we do not want to the bad links juice to flow to our new domain. Can we do a 301 with nofollow and will that have any negative impact or any impact at all.? any suggestion is greatly appreciated. Thank you Nick We are planning on moving to a different domain after 10 years, and laying off bunch of people due to loss of revenue.
Technical SEO | | orion680 -
Wordpress Redirect Plugin Vs Manual .htaccess?
Hi everyone, I need to 301 redirect my old pages to new ones but i am confused between whether to choose plugin for this or i should manually rewrite the code on .htaccess file. Please give your suggestion and if you think i should use plugin then which one?
Technical SEO | | himanshu3019890 -
301 Redirect with index.asp
I am very new to all of this so forgive the newbie questions I will get better. Ok so after starting a campaign I see that I have many issues including where some pages are being deemed as duplicate content. 1. The report says the http://lucid8.com has duplicate content on 2 other pages 2. When I look at them it shows that http://lucid8.com/index.asp and http://www.lucid8.com are duplicates. 3. Really these are the exactly the same page because the default page that is opened for www.lucid8.com http://www.lucid8.com etc always opens the index.asp page. 4. Now I read that I should do permanent redirects and how to do this via IIS and I tried to do a redirect from index.asp to www.lucid8.com but that does not work because www.lucid8.com is pointing to index.asp and so we end up in a circle. So the question is how do I get rid of these duplicate page references without causing problems. Thanks
Technical SEO | | TroyW0 -
How do I fix a 301 Redirect Loop?
Saturday I waas doing some correcting of some duplicate titles, including nofollowing tags, etc. (my main problem was duplicate titles due to tags and categories being indexed). Now this morning I see that one of my pages refuses to load, citing a 301 redirect loop. http://www.incredibleinfant.com/feeding/switching-baby-formula/ Originally, the page was posted under the wrong category. http://www.incredibleinfant.com/uncategorized/switching-baby-formula I resaved it under the correct category (feeding) and now it won't load. Can someone help me figure out how to correct this mess? Thanks so much Heather
Technical SEO | | Gotmoxie0 -
Can I remove 301 redirects after some time?
Hello, We have an very large number of 301 redirects on our site and would like to find a way to remove some of them. Is there a time frame after which Google does not need a 301 any more? For example if A is 301 redirected to B, does Google know after a while not to serve A any more, and replaces any requests for A with B? How about any links that go to A? Or: Is the only option to have all links that pointed to A point to B and then the 301 can be removed after some time? Thank you for you you help!
Technical SEO | | Veva0 -
Does it really matter to maintain 301 redirect after de-indexing of old URLs?
Today, I was reading latest blog post on SEOmoz blog about. Uncrawled 301s - A Quick Fix for When Relaunches Go Too Well This is very interesting study about 301 & How it useful to maintain traffic. I'm working on eCommerce website and I have done similar stuff on my website. I have big confusion to manage 301 redirect. My website generates new URLs due to following actions. Re-write dynamic URLs. Re-launch entire website on different eCommerce platform. [osCommerce to Magento Commerce] Re-name category. Trasfer one product from one category to another category. I'm managing my 301 redirect with old practice. Excel sheet data from Google webmaster tools and set specific new URLs for redirect. Hoooo... Now, I have 8.5K redirect in htaccess... And, I'm thinking it's too much. Can we remove old 301 redirect from htaccess or not? This is big question for me. Because, all pages are not hyperlink on external website. Google have just de-indexed old URLs and indexed new URLs. So, Is it require to maintain 301 redirect after Google process?
Technical SEO | | CommercePundit0