简体   繁体   中英

Multisite Wordpress, SSL and htaccess to use the subfolder as a root

I have an SSL sertificate, so http -> https is a must (as a precaution). I intend to have multiple subdomains, ie subdomain1.example.com, subdomain2.example.com, currently there is one subdomain that works without any issues. I'm using a multisite Wordpress setup, that was installed (purposely) in one subfolder. The multisite setup is for other languages. The current server folder layout is as follows:

  • public_html
    • backstage
      • subdomain1 (folder for the subdomain)
    • frontstage
      • wp-admin
      • wp-content
      • wp-includes
      • (the rest of the WP files)
    • index.php (a test file, that shouldn't load if the redirection is set up properly)

Currently, the www.example.com/frontstage/ opens the main WP site, this is fine. I can access its wp-admin without issues. www.example.com/frontstage/en/ shows a 404 page, this is not fine. www.example.com/frontstage/en/wp-admin/ opens the dashboard fine for the other site.

I want to retain the stripping out of index.php from any links (to keep the links clean).

There are two "simple" things to configure properly:

  1. I want to retain the server folder structure as it is, but having the "frontstage" folder skipped, so that when you visit www.example.com, the main WP site loads (and in the case someone would load www.example.com/frontstage/ it would redirect to www.example.com). Naturally, the "shift" needs to allow for the www.example.com/en/ to open the secondary website (any any other language sites that may follow). Ideally without rewriting all the links within the WP sites.
  2. Currently the /en/ site doesn't load its root. The demo posts and pages load fine.

My current .htaccess on the root level looks like this:

# disable index.php from urls

RewriteEngine On
RewriteBase /

<IfModule mod_rewrite.c>
    # redirect index.php requests
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

# force https and www

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

# move wordpress one level up

# allow subdomain

RewriteRule ^backstage\/subdomain1\/?(.*)$ "https\:\/\/subdomain1\.example\.com\/$1" [R=301,L]

Any help with this is highly appreciated (I'm still learning the htaccess bits and tricks and this one is truly beyond me). What am I missing in the above code to get it right?

When I have WP installed within a subfolder, I just goto Settings => General and change the Website URL by removing the subfolder.

Afterwards I move the file index.php one folder level up and in your case, would change it to:

 require( dirname( __FILE__ ) . '/frontstage/wp-blog-header.php' );

Does this solve your problem?

Find a detailed description how to move WP to a subdirectory on this site - You can find a detailed description about putting Wordpress in a subdirectory on the following website https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

Regarding a redirection from http to https - this is possible within the .htaccess. Much better, in my opinion, would be an alias on the apache (this usually should be done by your hoster).

The difference:

The htaccess redirect goes back to the user and then again to the server, which costs some time. The alias is - as far as I know - redirected on the server.

if you want to force https, you can do it with the following entry.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM