Can anyone share with me the difference between [R=301]
and [R=301,L]
in a 301 redirect? Which is best suited to redirect urls?
While both works perfectly fine, I do noticed that [R=301,L]
changes the URL to the new URL while [R=301]
only redirects the contents.
Can anyone share some insight on this please?
*). The next part is also important since it does the 301 redirects for us automatically: [L, R=301]. L means this is the last rule in this run. After this rewrite, the webserver will return a result. The R=301 means that the web server returns a 301 moved permanently to the requesting browser or search engine.
In this article I will give you a quick overview of what RewriteCond is and How it is used with RewriteRules. RewriteCond is an apache mod-rewite directive which is used for conditional URL rewriting on Apache server. We use RewriteCond along with RewriteRule%{HTTP_HOST} , %{HTTPS} etc.
NC|nocase. Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner.
L (last - stop processing rules) Last rule: instructs the server to stop rewriting after the preceding directive is processed. N (next - continue processing rules) NC (case insensitive) NE (do not escape special URL characters in output) NS (ignore this rule if the request is a subrequest)
Irrespective of R=301
there L
flag means Last
and should be placed in rules when you want to mark end a particular rewrite rule.
As per the official doc:
The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed. This corresponds to the last command in Perl, or the break command in C. Use this flag to indicate that the current rule should be applied immediately without considering further rules.
R
makes a redirect and L
forbids to apply any rules below this one. If there are no L
then the rest rules will be applied to the new URL.
Official documentation says:
You will almost always want to use [R] in conjunction with [L] (that is, use [R,L]) because on its own, the [R] flag prepends http://thishost[:thisport] to the URI, but then passes this on to the next rule in the ruleset, which can often result in 'Invalid URI in request' warnings.
The main difference between the flags [L] and [R=301,L] is that the R flag causes an explicit external HTTP redirect (there is one exception) while without the R flag the rule could also cause just an implicit internal redirect, depending on the actual rule and request.
The optional status code just specifies the type of the redirection response. 301 denotes a permanent redirect:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With