2017-02-18 83 views
0

我设置了我的Web服务器,创建了一个.htaccess文件和'www'的子目录,我在其中放置了我的Wordpress安装。使用.htaccess将所有文件/目录重定向到一个子目录,但不包括主页

运行安装后,所有内容似乎都会重定向,因为包含在.htaccess文件中的重定向规则正在将/ www /添加到URL中,导致出现404错误的主页除外。

猜测这可能是简单的,但需要一些客观的帮助。

显然,我的实际域名已经被代替“domain.com”

# Turn off indexing of files and directories. 
Options -Indexes 

# Turn on rewrites. 
RewriteEngine on 

# Force HTTPS 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

# Don't apply to URLs that go to existing files or folders. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# Only apply to URLs that aren't already in the subdirectory. 
RewriteCond %{REQUEST_URI} !^/www/ 

# Rewrite all those to insert the subdirectory name. 
RewriteRule ^(.*)$ /www/$1 

# Redirect the root folder. 
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ 
RewriteRule ^(/)?$ www/ [L,R=301] 

回答

0

原来这是一个简单的修复,就像我的第一个念头。

通过用[L]替换[L,R=301]中的最后一组规则,防止主页通过添加子目录回到自身。

相关问题