• Hey,

    I have a cname on my domain cname.domain.com which is linked to an host containing my WP install.

    I’m trying to make http://www.domain.com/blog/ redirect the traffic to cname.domain.com, masking the url (so the links appear like http://www.domain.com/category/some-post/)….

    This is my htaccess on http://www.domain.com:

    RewriteCond %{HTTP:Host} ^(?:www\.)?domain\.com$
    RewriteCond %{REQUEST_URI} ^/blog/(.*)
    RewriteProxy blog(.+) http\://cname.domain.com/$1 [L]

    Which works fine as far as masking/redirecting.
    My only problem is that i’m receiving 404 errors for all inner pages/posts on WP.

    I also went to the WP admin panel and changed the “Site Address (URL)” field to “www.domain.com/blog”.

    I’m not sure what’s the problem… If anyone have any ideas, or experience on the subject…. i’d really appreciate the help.

    Best regards and Thanks in advance.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Are you putting those directives above the WordPress permlink directives?

    Begin WordPress

    You could also try this:

    RewriteRule ^blog/(.*)$ http://cname.domain.com/$1 [R=301,L]

    Also in

    RewriteProxy blog(.+) http\://cname.domain.com/$1 [L]

    The target is not a regular expression so you don’t need to escape anything.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    I also went to the WP admin panel and changed the “Site Address (URL)” field to “www.domain.com/blog”.

    Don’t do that. You’ll be sending them to cname.domain.com/blog/blog/something/. Try putting it back as it was for now.

    My only problem is that i’m receiving 404 errors for all inner pages/posts on WP.

    If the above doesn’t work, on your new location, try resetting your permalinks. If the URLs match with the /blog/ infront of them, you should be fine.

    http://codex.wordpress.org/Using_Permalinks#Using_.22Pretty.22_permalinks

    Also I don’t think the original .htaccess is right exactly. Try 301 instead of RewriteProxy.

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule (.*) http://cname.domain.com/blog/$1 [R=301,L]
    </IfModule>

    Edit: Doh! Mickey beat me.

    Thread Starter hanan.baroz

    (@hananbaroz)

    I should have explained better….

    The domains are being hosted in two different hosting servers….

    So: http://www.domain.com points to server1 (that’s where my “custom” htaccess (mentioned above) resides).
    And cname.domain.com points to server2 (which contains my wp installation)

    That’s why i’m using RewriteProxy because one server is linking to the other.
    If i use RewriteRule it won’t mask the URL but redirect it to cname.domain.com.
    As i mentioned, the url should eventually look like this: http://www.domain.com/blog/wordpress-stuff/

    Regarding the target address, i’ll fix it, thanks. 🙂

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    The domains are being hosted in two different hosting servers….

    Yes, that’s why we use 301. The old server will send the browser to the new server location. They could be on the same host or on the opposite sides of the world with different hosting providers.

    That’s why i’m using RewriteProxy because one server is linking to the other.

    Unless I’m totally drawing a blank (very possible *sips more coffee*) the really, don’t do that. The two servers are independent. If you want readers that hit the old URLs on the old server to go to the new URL on the new server then you want to use 301s.

    Thread Starter hanan.baroz

    (@hananbaroz)

    There’s no old or new.
    both will still continue working (also, there’s only one wp install – on server 2)

    this is the behavior i’m trying to achieve:
    whenever a surfer goes to http://www.domain.com/blog the browser will be pointed to the “source” files on cname.domain.com (and not redirected). the url, on the address bar must remain http://www.domain.com/blog/.

    I want all the inner links on the WP server to appear as

    http://www.domain.com/blog/category/post-name1/
    http://www.domain.com/blog/category/post-name2/
    etc…

    (that’s why i made the change in the wp-admin settings)

    but the source files (wp installation, images and so on) will remain on cname.domain.com…

    thanks again to you both.
    and i’m sorry if i wasn’t clear enough about my problem.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    whenever a surfer goes to http://www.domain.com/blog the browser will be pointed to the “source” files on cname.domain.com (and not redirected). the url, on the address bar must remain http://www.domain.com/blog/.

    *sips much, much, much more coffee* I think I got it now…

    So the users are still going to http://www.domain.com and you want to preserve the URL that their going to BUT in reality the whole enchilada exists on cname.domain.com. Only you want the user to see and believe they’re still on http://www.domain.com and let Apache on www reverse proxy the requests to the other server on cname.

    http://www.domain.com only has the .htaccess file, everything else is on cname.domain.com, the php, jpeg, etc.

    Why not just move the DNS name to point to the new server…?

    Thread Starter hanan.baroz

    (@hananbaroz)

    yes, you got it.

    as for the question “why”….
    because http://www.domain.com contains a different partition of the website (it’s a big website). that’s why i said http://www.domain.com/blog/ should point there, so the surfer “stay” under one roof.

    Obviously i can stick with the cname.domain.com instead. but for SEO (damn’ you google! – i hope i don’t upset the internet gods :)) purposes i need to have it in this specific format: http://www.domain.com/blog/

    *refills Jan Dembowski coffee* 😉

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    because http://www.domain.com contains a different partition of the website (it’s a big website). that’s why i said http://www.domain.com/blog/ should point there, so the surfer “stay” under one roof.

    Gotcha. There is a way to do it with Apache2’s proxy module (reverse proxy) but it’s dicey and I think it’s a bit CPU intensive too. Plus you have to make sure that all other proxy requests are denied.

    Obviously i can stick with the cname.domain.com instead. but for SEO (damn’ you google!

    Darn you Search Engines!! Daaarrrnnn yooouuuu!!!

    Huh, that’s a tough one. The 301s will sort out the gods of The Search Engine but this may make it easier:

    Set the http://www.domain.com to /blog/ and leave it there. Don’t do the cname bit yet just make sure that http://www.domain.com/something/ goes to http://www.domain.com/blog/something/. Wait a few days and your search engine results should adjust. Use Google’s Webmaster tools and a sitemap plugin if you haven’t already.

    Once the search engine has updated consider redirecting the blog portion to cname.domain.com later on.

    *refills Jan Dembowski coffee* 😉

    Thanks! Was getting low.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘htaccess, wordpress and cnames’ is closed to new replies.