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 having a problem running Apache 2.2.20 on a Linux Mint distro.

I've got the following rule in my .htaccess file:

RewriteEngine on
RewriteRule old1/old2 http://localhost/new1 [P]

When I browse to http://localhost/old1/old2 I just get a redirect to localhost/new1, that is, the new URL shows in the address bar. I want the "old1/old2" URL to show (with the page content from /new1). What am I doing wrong?

I've installed mod_proxy and mod_proxy_http (i.e. "a3enmod proxy", "a2enmod proxy_http").

Many thanks in advance for any help you can give me.

share|improve this question
add comment

2 Answers

I think you also need a ProxyPassReverse statement. Here's an example from http://httpd.apache.org/docs/2.4/rewrite/proxy.html

RewriteEngine  on
RewriteBase    /products/
RewriteRule    ^widget/(.*)$  http://product.example.com/widget/$1  [P]
ProxyPassReverse /products/widget/ http://product.example.com/widget/
share|improve this answer
    
Unfortunately this needs to be done in a .htaccess file, where ProxyPassReverse is not permitted. –  Monkeybrain Jan 18 '13 at 14:44
add comment

If both resources are on the same web-server, simply do an internal rewrite e.g.

RewriteEngine on
RewriteRule old1/old2 /new1 [L]
share|improve this answer
    
This would mean /new1 was visible in the URL wouldn't it? I want to fetch data from /new1 but display the requested URL old1/old2 ? –  Monkeybrain Jan 18 '13 at 14:34
    
No, the old URL will remain visible, as an INTERNAL not a CLIENT rewrite. –  arober11 Jan 18 '13 at 14:44
    
Just tried that and unfortunately I'm not seeing that happening - the browser gets the /new1 page but also the /new1 URL. –  Monkeybrain Jan 18 '13 at 14:54
    
The above syntax will perform an internal rewrite (does not alter the URL in the browser), so try another browser flavour. If the rule still doesn't work an earlier rule or syntax error is likely to be at fault, in your config. If your other browser works as expected, clear the browser cache on the other browser, and re-test. See: Rewriting From Old to New (external) –  arober11 Jan 18 '13 at 15:39
    
That's a useful link, thanks. It does seem to be saying the opposite though - From Old To New (Internal) uses the [PT] flag, which doesn't change the URL in the browser, while From Old To New (External) does not specify the proxy flag, and therefore the URL does change in the browser. Therefore I need to use the proxy flag [P] ? –  Monkeybrain Jan 18 '13 at 15:57
show 1 more comment

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.