0

I was going through the rewrite rules and saw this:

RewriteRule ^(.*)/$ $1 [R=permanant]

I checked Apache's RewriteRule Flags list, but cannot find any info there.

Is it an alias to 301?

2 Answers 2

3

A more useful reference would be alongside the one you quoted, at https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

RewriteRule ^(.*)/$ $1 [R=permanant]

There's an error in this line (permanent is misspelt), but assuming that's a typo in the question rather than in your Apache configuration, here's what the line says:

  • RewriteRule - it's a URL rewriting rule from mod_rewrite
  • ^(.*)/$ - match the RE that describes anything at all, ending with /, and remember everything as $1 except that trailing /
  • $1 - if found, prepare to use the match group we just found (i.e. the original URL without a trailing /)
  • [R=permanent] - send a Redirect instruction to the web browser tagged as permanent, i.e. HTTP 301

In other words, as pointed out in a comment, it will redirect the web browser from any URL path on this server ending with a slash to one without.

3
  • 3
    Put more succinctly, it will redirect from e. g. https://www.example.com/directory/ to https://www.example.com/directory. Commented Jul 3, 2024 at 8:20
  • 1
    @DopeGhoti thank you! Commented Jul 3, 2024 at 11:44
  • @ChrisDavies "permanant" is an actual rewrite rule in our config (just started on the job and was going through the existing config) Commented Jul 5, 2024 at 8:03
1

In addition to Chris's answer, a full explanation of the following regular expression ^(.*)/$ $1:
^ is identified as the beginning of the string.
() used to create a capture group
(.*) This means match anything
$ This means the end of the string
$1 refers to the first capture in the group

when you combine them you will get capture matches for any URL that ends with a slash (/) then take the first one.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.