.htaccess& mod_rewrite重定向问题

时间:2013-01-15 01:05:56

标签: .htaccess mod-rewrite

好的。我没有运气。所以我想我会看看你们是否都能帮助理解这个问题。

我继承了一个以前有很多不同子域名的网站,这些子网站现在都被写入.htaccess文件,重写为子目录(即 blog.site.com 成为< EM> site.com/blog )。

为避免重复内容问题,我还需要将所有 site.com 网址重写为 www .site.com < / em>的。即使当前的规则对我来说很好,但它们显然不会重写域的所有子目录。 (对于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 /目录的任何想法?我在这里缺少什么?

0 个答案:

没有答案