Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to set up a mod_rewrite rule so that when the webpage www.mysite.com/blog is requested a page from the blogging service Tumblr is loaded. I have set up my Tumblr site so that blog.mysite.com returns the domain. Currently, www.mysite.com/blog redirects to blog.mysite.com. What I want is www.mysite.com/blog to display blog.mysite.com and for the user not to be aware of blog.mysite.com. I have tried several difference approaches to achieve this. First, I tried to use a rewrite rule:

RewriteEngine On    # Turn on the rewriting engine
RewriteRule  /blog/   http://blog.mysite.com/    [NC,P,L]    

Then a 'ProxyPass' (attempt 1)

ProxyPass /blog/ http://blog.mysite.com/

and attempt 2:

<Location /blog/>
    ProxyPass http://blog.mysite.com/
</Location>

Then, I saw another more sophisticated mod_rewrite rule which I also tried:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^mysite.com/blog$
    RewriteCond %{REQUEST_URI} !/standard
    RewriteRule ^(.*)$ http://blog.mysite.com$1   [R]
</IfModule>

I would appreciate any advice on how best to do this.

share|improve this question
    
Can you clarify what the problems were with the proxying approach? –  Shane Madden May 5 '13 at 18:01
    
The url was not rewritten - it successfully redirected, but it was clear that the url had changed in the browser from mysite.com/blog to blog.mysite.com –  celenius May 5 '13 at 18:11
    
So you were proxying to mysite.tumblr.com, which was then redirecting to blog.mysite.com, is that correct? Do you get redirected when you visit mysite.tumblr.com directly in your browser? It sounds like this is caused by tumblr's handling of these requests, it might be completely out of your control. –  Shane Madden May 5 '13 at 18:18
    
Apologies, I just realized that I had got confused as I wrote the question. blog.mysite.com is fine, it's just the secret redirect between mysite.com/blog that I am trying to do. –  celenius May 5 '13 at 18:39

2 Answers 2

You don't mention specific issues for each case, but in my experience the best thing to do, when trying to debug RewriteRules, is to turn on the rewrite log and crank up the rewriteloglevel. This will display the incoming request, and the pass/fail for each rule, as well as what it does with the request when it matches a rule.

RewriteLog "/usr/local/var/apache/logs/rewrite.log"
RewriteLogLevel 3

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteloglevel

Remember to disable this once you've finished, as it does cause a performance hit, especially at 3 and above.

share|improve this answer
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^mysite.com/blog$
    RewriteCond %{REQUEST_URI} !/standard
    RewriteRule ^(.*)$ http://blog.mysite.com$1   [R]
</IfModule>

That rule is almost correct, it should be:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^mysite.com$
    RewriteCond %{REQUEST_URI} !/standard
    RewriteRule ^(.*)$ http://blog.mysite.com$1   [R]
</IfModule>

Try that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.