WordPress Multisite .htaccess .. please explain the functionality

What is this .htaccess file doing??? I don’t know anything about .htaccess .please help.

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]

Related posts

Leave a Reply

1 comment

  1. RewriteEngine On
    

    This turns on the rewrite engine, all the rules get ignored if this isn’t in the htaccess file

    RewriteBase /
    

    This tells the rewrite engine that relative URL-paths should use this as its base

    RewriteRule ^index.php$ - [L]
    

    This rule means: “If the request is index.php, then pass it through the rewrite engine and stop rewriting”

    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    

    This rule matches against <some stuff> then wp-admin, and redirects the browser to the same URL except it ends with a slash. Example: http://example.com/foo/bar/wp-admin gets redirected to http://example.com/foo/bar/wp-admin/

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    

    This rule says if the request is for a file or directory that exists, pass it through the rewrite engine and stop rewriting.

    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    

    This rule matches against <some stuff> then wp-content or wp-admin or wp-includes, and rewrites the URI to everything after the <some stuff> Example: http://example.com/blah/blah/wp-admin/some/more gets rewritten to /wp-admin/some/more.

    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
    

    This rule matches against <some stuff> followed by any php file, and rewrites the URI to everything after the <some stuff>. Example: http://example.com/abc/123/somefile.php gets rewritten to /somefile.php.

    RewriteRule . index.php [L]
    

    Finally, if none of the other rules got applied, this rule rewrite everything else to /index.php.