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
-
301 redirect from dynamic url to static page
Hi, i want to redirect from this old link http://www.g-store.gr/product_info.php?products_id=1735/ to this one https://www.g-store.gr/golf-toualetas.html I have done several attempts but with no result. I anyone can help i will appreciate. My website runs in an Apache server with cpanel. Thank you
Technical SEO | | alstam0 -
301 Redirect non existant pages
Hi I have 100's of URL's appearing in Search Console for example: ?p=1_1 These go to on to 5_200 etc.. I have tried to do htaccess and the mod rewrite is on as I can redirect directories to the root i.e RewriteRule ^web_example(.*)$ /$1 [R=301,N,L] However I have tried all kinds of variations to redirect ?p= and either it doesn't work at all or it crashes the website. Can anyone point me in the right direction to fix this.
Technical SEO | | Cocoonfxmedia0 -
Will a Robots.txt 'disallow' of a directory, keep Google from seeing 301 redirects for pages/files within the directory?
Hi- I have a client that had thousands of dynamic php pages indexed by Google that shouldn't have been. He has since blocked these php pages via robots.txt disallow. Unfortunately, many of those php pages were linked to by high quality sites mulitiple times (instead of the static urls) before he put up the php 'disallow'. If we create 301 redirects for some of these php URLs that area still showing high value backlinks and send them to the correct static URLs, will Google even see these 301 redirects and pass link value to the proper static URLs? Or will the robots.txt keep Google away and we lose all these high quality backlinks? I guess the same question applies if we use the canonical tag instead of the 301. Will the robots.txt keep Google from seeing the canonical tags on the php pages? Thanks very much, V
Technical SEO | | Voodak0 -
301 redirect to WWW on a 2 year old website with good SERPs and organic traffic?
Hi everyone, Recently someone pointed out that my website can be accessed in both ways i.e. by typing www.example.com or example.com. He further added that Google might identify this as duplicate content and penalize my website. So now I'm thinking about 301 redirection from non WWW to WWW using htaccess method. But my website is 2 year old now and I'm getting some decent traffic from Google. Will this redirection have an adverse effect on my rankings? Is there any other way to resolve this issue? I don’t want to lose my current rankings or organic traffic. Any help would be very much appreciated. P.S. Currently Google index my website pages with WWW.
Technical SEO | | nicksharma040 -
Best Practice - Disavow tool for non-canonical domain, 301 Redirect
The Situation: We submitted to the Disavow tool for a client who (we think) had an algorithmic penalty because of their backlink profile. However, their domain is non-canonical. We only had access to http://clientswebsite.com in Webmaster Tools, so we only submitted the disavow.txt for that domain. Also, we have been recommending (for months - pre disavow) they redirect from http://clientswebsite.com to http://www.clientswebsite.com, but aren't sure how to move forward because of the already submitted disavow for the non-www site. 1.) If we redirect to www. will the submitted disavow transfer or follow the redirect? 2.) If not, can we simply re-submit the disavow for the www. domain before or after we redirect? Any thoughts would be appreciated. Thanks!
Technical SEO | | thebenro0 -
301 how?
My website is www.photosbykristopher.com, but I have some important links pointing to photosbykristopher.com How do I get my domain without the www to redirect to the domain with the www. PS I use Go daddy for hosting.
Technical SEO | | KristopherWho0 -
301 Redirects
Hi, I ran the seomox link report and see that I have an entry for our home page (http://www.trophycentral.com/) and http://www.trophycentral.com/index.html. The index is shown with a 301 redirect. Does this mean that a redirect is already in place to http://www.trophycentral.com/? I want to ensure our traffic is not being split between the two urls, but not sure how to confirm this. Thanks! <colgroup><col width="294"></colgroup><colgroup><col width="81"></colgroup><colgroup><col width="80"></colgroup><colgroup><col width="77"></colgroup><colgroup><col width="214"></colgroup>
Technical SEO | | trophycentraltrophiesandawards
| URL | HTTP Status | Total Links | Page Authority | Number of Linking Root Domains |
| http://www.trophycentral.com/ | 200 | 5746 | 53 | 244 |
| http://www.trophycentral.com/index.html | 301 | 5123 | 42 | 4 |1 -
301 redirect .htaccess problem
Can anyone explain to me why this doesn't work? Redirect 301 /category/diamond-pendants/nstart/1/start/(.*) http://www.povada.com/category/pendants/nstart/1/start/$1 Im trying to replace everything after /start/ and insert it into the new url. Thanks in advance.
Technical SEO | | 13375auc30