• Hi,

    Have migrated a subdirectory multisite from Nginx to LiteSpeed, but I cannot figure out how to configure the htaccess rules.

    Simply the situation is that I need to 301 from abc.com/site1/a/ to abc.com/site1/a without the end trailing slash.

    I have tried most of the lines on the internet I can possibly find, they can work 301 for pages but cannot fix the too many redirect problem for wp-admin/ urls.

    The original htaccess is as follows:

    # BEGIN WordPress
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    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]
    </IfModule>
    
    # END WordPress

    I have tried rules like:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ /$1 [R=301,L]
    <IfModule mod_rewrite.c>
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [R=301,L]

    Most of the time, these rules can work well for the main site abc.com/wp-admin/ but will cause a redirect loop for sub-directory sites: abc.com/site1/wp-admin/

    Can anyone help with a doable redirect rule? thanks!

    • This topic was modified 2 years, 8 months ago by tolddsm.
    • This topic was modified 2 years, 8 months ago by tolddsm.
    • This topic was modified 2 years, 8 months ago by tolddsm.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Simply the situation is that I need to 301 from abc.com/site1/a/ to abc.com/site1/a without the end trailing slash.

    This works for me out of the box with the default WordPress Multisite .htaccess rules generated by WordPress (just tested this).

    All I had to do was ensure the permalink setting did not have the trailing slash ie /%postname% instead of /%postname%/

    Thread Starter tolddsm

    (@tolddsm)

    @gappiah
    Thanks for the reply but it does not work for me. The permalink is not enough for 301s

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘remove trailing slash from sub-directory multisite’ is closed to new replies.