> For the complete documentation index, see [llms.txt](https://htaccess.gitbook.io/htaccess/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://htaccess.gitbook.io/htaccess/what-is-l-in-qsa-l-in-htaccess.md).

# What is L in \[QSA, L] in htaccess

## [What is L in \[QSA, L\] in htaccess](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess)

Asked 9 years, 11 months agoModified [1 year, 2 months ago](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess?lastactivity)Viewed 107k times85

> QSA means that if there's a query string passed with the original URL, it will be appended to the rewrite (olle?p=1 will be rewritten as index.php?url=olle\&p=1.
>
> L means if the rule matches, don't process any more RewriteRules below this one.

Hi, what are some easy examples to explain the use of L? I can't seem to grasp this explanation above. Any help will be highly appreciated. Thanks.

* [.htaccess](https://stackoverflow.com/questions/tagged/.htaccess)
* [qsa](https://stackoverflow.com/questions/tagged/qsa)

[Share](https://stackoverflow.com/q/16468098)[Improve this question](https://stackoverflow.com/posts/16468098/edit)Followasked May 9, 2013 at 18:00[![stackoverflower's user avatar](https://www.gravatar.com/avatar/18ca829883de84fdae9d3ee92ca25db1?s=64\&d=identicon\&r=PG)](https://stackoverflow.com/users/2284106/stackoverflower)[stackoverflower](https://stackoverflow.com/users/2284106/stackoverflower)88911 gold badge77 silver badges55 bronze badges

* Check this link: [httpd.apache.org/docs/current/rewrite/flags.html#flag\_qsa](http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa) – [Jo Smo](https://stackoverflow.com/users/1286942/jo-smo) [Aug 7, 2014 at 18:06](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess#comment39224097_16468098)
* QSA flag in mod\_rewrite : [helponnet.com/2021/04/27/htaccess-qsa-flag](https://helponnet.com/2021/04/27/htaccess-qsa-flag/) – [Amit Verma](https://stackoverflow.com/users/3160747/amit-verma) [Jul 18, 2021 at 5:06](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess#comment120929458_16468098)

[Add a comment](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess#)

### 3 Answers

Sorted by:                                              Highest score (default)                                                                   Trending (recent votes count more)                                                                   Date modified (newest first)                                                                   Date created (oldest first)                              124

### .htaccess flag list

* C (chained with next rule)
* CO=cookie (set specified cookie)
* E=var:value (set environment variable var to value)
* F (forbidden - sends a 403 header to the user)
* G (gone - no longer exists)
* H=handler (set handler)
* **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)
* P (proxy - i.e., apache should grab the remote content specified in the substitution section and return it)
* PT (pass through - use when processing URLs with additional handlers, e.g., mod\_alias)
* R (temporary redirect to new URL)
* R=301 (permanent redirect to new URL)
* QSA (append query string from request to substituted URL)
* S=x (skip next x rules)
* T=mime-type (force specified mime type)

Flags are added to the end of a rewrite rule to tell Apache how to interpret and handle the rule. They can be used to tell apache to treat the rule as case-insensitive, to stop processing rules if the current one matches, or a variety of other options. They are comma-separated, and contained in square brackets.

[Share](https://stackoverflow.com/a/39225280)[Improve this answer](https://stackoverflow.com/posts/39225280/edit)Follow[edited Aug 30, 2016 at 10:54](https://stackoverflow.com/posts/39225280/revisions)answered Aug 30, 2016 at 10:39[![Smit Patadiya's user avatar](https://lh6.googleusercontent.com/-h1wLrf4-6YQ/AAAAAAAAAAI/AAAAAAAABiE/VD1oCMnOh6I/photo.jpg?sz=64)](https://stackoverflow.com/users/6678050/smit-patadiya)[Smit Patadiya](https://stackoverflow.com/users/6678050/smit-patadiya)1,38811 gold badge88 silver badges66 bronze badges

* 2You got my +1, but for a *perfect* answer, it would be nice to provide a link to Apache's official resources, e.g. [httpd.apache.org/docs/current/mod/mod\_rewrite.html#RewriteRule](https://httpd.apache.org/docs/current/mod/mod_rewrite.html#RewriteRule) (or wherever your reference was) – [Gwyneth Llewelyn](https://stackoverflow.com/users/1035977/gwyneth-llewelyn) [Jul 26, 2022 at 16:27](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess#comment129153049_39225280)

[Add a comment](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess#)102

The `QSA` flag means to append an existing query string *after* the URI has been rewritten. Example:

URL=`http://example.com/foo/bar?q=blah`

Rule:

```
RewriteRule ^foo/(.*)$ /index.php?b=$1
```

Result=`/index.php?b=bar`

Notice how the `q=blah` is gone. Because the existing query string is dropped in favor of the one in the rule's target, (b=$1). Now if you include a `QSA` flag:

```
RewriteRule ^foo/(.*)$ /index.php?b=$1 [QSA]
```

The result becomes=`/index.php?b=bar&q=blah`

***

The `L` flag simply means to stop applying any rules that follow. Given the same URL, `http://example.com/foo/bar?q=blah`, and given the rules:

```
RewriteRule ^foo - 

RewriteCond %{REQUEST_URI} !^/bar.php
RewriteRule ^(.*)$ /bar.php?z=$1 
```

The first rule gets applied and the URI gets passed through unchanged (via the `-` target). The rewrite engine then processes the next rule, and the URI gets rewritten to `/bar.php?z=foo/bar`. What happens when you add an `L` to the end:

```
RewriteRule ^foo - [L]

RewriteCond %{REQUEST_URI} !^/bar.php
RewriteRule ^(.*)$ /bar.php?z=$1 
```

The URL `http://example.com/foo/bar` gets passed through untouched from the first rule, then **stops** because of the `L` flag. If the URL is `http://example.com/something/else` then the first rule doesn't match and the second rule gets applied, rewriting the URI to: `/bar.php?z=something/else`

Note that since the rewrite engine loops through all the rules until the URI stops changing, the `L` flag will *not* prevent the looping, only any further rules from getting applied in the current iteration.

[Share](https://stackoverflow.com/a/16468677)[Improve this answer](https://stackoverflow.com/posts/16468677/edit)Followanswered May 9, 2013 at 18:32[![Jon Lin's user avatar](https://i.stack.imgur.com/kGxQa.gif?s=64\&g=1)](https://stackoverflow.com/users/851273/jon-lin)[Jon Lin](https://stackoverflow.com/users/851273/jon-lin)141k2929 gold badges216216 silver badges218218 bronze badges

* QSA replaces `?` to `&`, making it impossible to distinguish between `/page&foobar` vs `/page?foobar`. How can I stop QSA from replacing `?` to `&`? – [Pacerier](https://stackoverflow.com/users/632951/pacerier) [Sep 27, 2017 at 6:06](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess#comment79837245_16468677)
* @Pacerier if you need to encode the query string in the new query string, then you may want to look into using the `%{QUERY_STRING}` variable instead of using QSA – [Jon Lin](https://stackoverflow.com/users/851273/jon-lin) [Sep 27, 2017 at 14:32](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess#comment79856786_16468677)

[Add a comment](https://stackoverflow.com/questions/16468098/what-is-l-in-qsa-l-in-htaccess#)-1

Example of \[L,QSA]

> Before: *<https://example.com/index.php?user=robert>*

```
RewriteEngine On
RewriteRule ^user/([^/]+)?$ index.php?user=$1 [L,QSA]
```

> After: *<https://example.com/user/robert?query=value>*

You can also use other query too.

> Like: *robert?query=value\&query2=value2\&query3=value3*

[Share](https://stackoverflow.com/a/70753932)[Improve this answer](https://stackoverflow.com/posts/70753932/edit)Follow<br>
