没有条件的Apache Mod_rewrite条件

时间:2014-10-29 07:55:00

标签: wordpress apache mod-rewrite blogs

我的档案在这里

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-clubs但other than this it redirect to blog.myste.com/<Page-link>请一些一个人帮帮我。

1 个答案:

答案 0 :(得分:0)

首先放置/blog/网址,然后检查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中检查网址路径作为模式。

在检查/home等时,您也错过了前导斜杠。仅在.htaccess文件或RewriteRule指令中使用Directory时忽略斜杠。

最后请注意,不要使用R=301进行测试,请参阅此答案Tips for debugging .htaccess rewrite rules了解详细信息。