【发布时间】:2019-04-26 16:49:48
【问题描述】:
我有一个 SSL 证书,所以 http -> https 是必须的(作为预防措施)。我打算拥有多个子域,即 subdomain1.example.com、subdomain2.example.com,目前有一个子域可以正常工作。我正在使用多站点 Wordpress 设置,它(故意)安装在一个子文件夹中。多站点设置适用于其他语言。当前服务器文件夹布局如下:
- public_html
- 后台
- subdomain1(子域的文件夹)
- 前台
- wp-管理员
- wp 内容
- wp 包含
- (其余的 WP 文件)
- index.php(一个测试文件,如果重定向设置正确,则不应加载)
目前,www.example.com/frontstage/ 打开了主要的 WP 站点,这很好。我可以毫无问题地访问它的 wp-admin。 www.example.com/frontstage/en/ 显示 404 页面,这不好。 www.example.com/frontstage/en/wp-admin/ 为其他站点打开仪表板。
我想保留从任何链接中删除 index.php(以保持链接干净)。
有两个“简单”的东西可以正确配置:
- 我想保留服务器文件夹结构,但跳过“frontstage”文件夹,这样当您访问 www.example.com 时,主 WP 站点会加载(如果有人会加载 www.example.com)。 example.com/frontstage/ 它将重定向到 www.example.com)。自然地,“转变”需要允许 www.example.com/en/ 打开辅助网站(可能跟随的任何其他语言网站)。理想情况下,无需重写 WP 网站内的所有链接。
- 目前 /en/ 站点不加载其根目录。演示帖子和页面加载正常。
我当前在根级别的 .htaccess 如下所示:
# 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]
对此的任何帮助都非常感谢(我仍在学习 htaccess 的位和技巧,而这真的超出了我的能力范围)。我在上面的代码中遗漏了什么来使它正确?
【问题讨论】:
标签: php wordpress .htaccess ssl multisite