在子文件夹问题

时间:2017-12-25 12:52:27

标签: wordpress apache .htaccess mod-rewrite

我有一个共享的Linux主机,我想在其上托管2个网站 在/public_html/我已托管example.com/public_html/example2/已托管example2.com

.htaccess example.com

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

#Custom Error Pages
ErrorDocument 403 https://www.example.com/error-403/

.htaccess example2.com

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

#Custom Error Pages
ErrorDocument 403 http://www.example2.com/error-403/

我想分别使用www版本访问该网站,即

请注意:我在WordPress常规设置中设置了site_urlhome_url及以上给定的网址。

我面临的问题是

当我访问example2.com时,它会转到https://www.example.com/example2/

因此,在阅读this answer后,我将.htaccess的{​​{1}}更改为

example.com

所以现在可以访问# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # if request is not for the /example2/ RewriteCond %{REQUEST_URI} !^/example2/ [NC] # otherwise forward it to index.php RewriteRule . /index.php [L] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] </IfModule> # END WordPress 但永久链接不起作用所以当我尝试重置它时,它会删除我的example2 example2.com文件的内容并将我重定向到.haccess。< / p>

任何人都可以帮助我吗?

我也试过这个没有运气Configuring WordPress .htaccess to view subfolders

1 个答案:

答案 0 :(得分:0)

我认为例2的htaccess应该是这样的:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
 RewriteBase /example2
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
 </IfModule>
 # END WordPress

 #Custom Error Pages
 ErrorDocument 403 http://www.example2.com/error-403/