2014-10-29 42 views
0

我的文件是在这里阿帕奇mod_rewrite的条件与NOT条件

PassengerMaxPoolSize 25 
PassengerPoolIdleTime 10 
<VirtualHost *:80> 
     RailsEnv development 
     # !!! Be sure to point DocumentRoot to 'public'! 
     DocumentRoot /myapp/public 
     <Directory /myapp/public> 
     # This relaxes Apache security settings. 
     AllowOverride All 
     # MultiViews must be turned off. 
     Options -MultiViews 
     </Directory> 
     RewriteEngine On 
     ErrorDocument 503 /system/maintenance.html 


#  RailsAllowModRewrite on 

     RewriteCond %{REQUEST_URI} !^(home|book-club|blog|login|book-clubs|)$ [NC] 
     RewriteRule .? http://blog.mysite.com%{REQUEST_URI} [R=301,L] 
     RewriteCond %{REQUEST_URI} ^/blog 
     RewriteRule ^/blog/?(.*)$ http://blog.mysite.com/$1 [P,NC,R=301,L] 
     ProxyPass   /blog/ http://blog.mysite.com/ 
      ProxyPassReverse /blog/ http://blog.mysite.com/ 

</VirtualHost> 

<VirtualHost *:80> 
    ServerName blog.mysite.com 
    DocumentRoot /var/www/wordpress 
    <Directory /var/www/wordpress/> 
    Options FollowSymLinks 
    AllowOverride All 
    Options -Indexes 
    Order allow,deny 
    allow from all 
    </Directory> 
</VirtualHost> 

我想,当用户打http:://www.mysite.com/homehttp:://www.mysite.com/book-clubs重定向到mysite.com/home和http :: //www.mysite.com/book-俱乐部,但other than this it redirect to blog.myste.com/<Page-link>请有人帮助我。

回答

0

先放/blog/ URL,然后检查homebook-club

RewriteRule ^/blog/(.*)$ http://blog.mysite.com/$1 [NC,R,L] 
RewriteRule !^/(home|book-club|login|book-clubs|)$ http://blog.mysite.com%{REQUEST_URI} [R,L] 

你不需要RewriteCond,您可以检查作为RewriteRule模式的URL路径。

当检查/home等仅省略了斜线,使用RewriteRule .htaccess文件或Directory指令内时,也错过了领先的斜线。

作为最后一个注意事项,请勿使用R=301进行测试,详情请参阅此答案Tips for debugging .htaccess rewrite rules

+0

谢谢@olaf它的工作就像一个魅力 – 2014-10-30 05:44:02