Search code examples
mod-rewriteclean-urls

using mod_rewrite to point at a blog


I'm trying to use mod_rewrite to point the blog portion of a site to a blog site.

this is what I have to handle the normal stuff

RewriteRule ^(\w+)/?$ index.php?page=$1

This is what i'm trying to use for the blog site

RewriteRule ^blog/?$ http://url.to.my.blogger.site

but it's not working, when I go to site/blog it directs me to index.php?page=blog is there something I need to do to not do the second rewrite if the first is correct? like an if/else? sorry don't know much about mod_rewrite so any advice would be awesome.

also I noticed that if I try to do something like site/home everything works fine but if I attempt to hit site/home/ it puts all of my urls into the wrong context, for example my css and images don't get loaded correctly.

my full file is this

RewriteEngine on

RewriteRule ^blog/?$ remote/blog/uri/here

RewriteRule ^(\w+)/?$ index.php?page=$1

RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^index\.php - [F]

and when i hit site/blog it still tries to serve index.php?page=blog, I'm guessing I have to break out of the code at some point? I couldn't find documentation on if/else statements


Solution

  • I needed to add flags to my RewriteRule lines so that the server wouldn't evaluate further. Changing them to be

    RewriteRule ^/blog http://url.to.blog [L]
    

    did the trick, the problem was that it was evaluating all the way down, seeing as I wasn't attempting to go to index the last valid rule to evaluate was the general rewrite rule.