好吧。我没有运气。所以我想我会看看你们是否可以帮助理解这个问题。
我继承了一个以前有很多不同子域的站点,这些子域现在都被写入 .htaccess 文件以重写为子目录(即blog.site.com变为site.com/blog)。
为避免重复内容问题,我还需要将所有site.com URL 重写为www .site.com。尽管当前的规则对我来说看起来不错,但它们显然并没有重写域的所有子目录。(我对 RegEx 的使用从未如此出色,因此这可能是问题的一部分。)
以下是 .htaccess 中的当前规则:
#---------------------------------
# Start rewrite engine
#---------------------------------
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{PATH_INFO} !^$
RewriteCond %{HTTP_HOST} !^localhost$ [NC]
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} !^blog\..+$ [NC]
RewriteCond %{HTTP_HOST} !^docs\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
#---------------------------------
# Rewrite some of our subdomains
#---------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.site\.com$ [NC]
RewriteRule (.*)$ "http://www.site.com/blog/$1" [R=301,QSA,L]
RewriteCond %{HTTP_HOST} ^docs\.site\.com$ [NC]
RewriteRule (.*)$ http://www.site.com/docs/$1 [R=301,QSA,L]
RewriteCond %{HTTP_HOST} ^wiki\.site\.com$ [NC]
RewriteRule (.*)$ http://www.site.com/wiki/$1 [R=301,L]
</IfModule>
#---------------------------------
# Wordpress specific - do not place anything below this line
#---------------------------------
# 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
(显然,其中一些是为了允许本地开发环境等而存在的)。
关于为什么我没有看到site.com/directory重写为www .site.com/directory的任何想法?我在这里想念什么?