2014-10-29 33 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