2

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. a2enmod proxy, a2enmod proxy_http).

3 Answers 3

2

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

RewriteEngine on RewriteRule old1/old2 /new1 [L] 
7
  • 1
    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 ? Commented Jan 18, 2013 at 14:34
  • No, the old URL will remain visible, as an INTERNAL not a CLIENT rewrite. Commented Jan 18, 2013 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. Commented Jan 18, 2013 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) Commented Jan 18, 2013 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] ? Commented Jan 18, 2013 at 15:57
1

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/ 
1
  • 1
    Unfortunately this needs to be done in a .htaccess file, where ProxyPassReverse is not permitted. Commented Jan 18, 2013 at 14:44
-2

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

If doesn't work try change "localhost" to "localhost:80".

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.