Search code examples
apache.htaccessurlmod-rewritemod-proxy

URL rewriting to replace URLs of original site


I have a site hosted on OpenShift, with a URL like https://myproject.myname-rhcloud.com/myapp. I deploy there via git, it works fine, but the URL is not exactly easy to remember.

Then I bought a domain name (say, http://www.first-last.fr), with a limited Apache hosting which allows me to deploy my own .htaccess there.

I tried to do a redirect from my registrar, but this ended up in a HTML frame which hid the title of the page: the title always showed the root URL, even in sub-folders of the site, so I saw http://www.first-last.fr even if I was visiting http://www.first-last.fr/myapp/glossary.

What I would like is access the real site (https://myproject.myname-rhcloud.com/myapp) via my new URL (http://www.first-last.fr), with the following constraints :

And this ideally without having to touch the original site.

I checked many similar questions of SO but I did not find a definitive answer on this specific request (I would be happy to be wrong, if so please show me the good links) !

I also tried to do URL rewriting but this was not successful, when I type http://www.first-last.fr/myapp my explorer shows https://myproject.myname-rhcloud.com/myapp.

EDIT: I tried mod_proxy, as Jack suggested. Here is my .htaccess:

SetEnv PHP_VER 5_TEST
SetEnv REGISTER_GLOBALS 0

Options +FollowSymLinks -MultiViews

ProxyPreserveHost On

# Turn mod_rewrite on
RewriteEngine On
# RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?first-last\.fr$ [NC]
RewriteRule ^ https://myproject.myname.rhcloud.com%{REQUEST_URI} [L,P]

# ProxyPass / https://myproject.myname.rhcloud.com/
ProxyPassReverse / https://myproject.myname.rhcloud.com/

I also tried with a simpler version:

SetEnv PHP_VER 5_TEST
SetEnv REGISTER_GLOBALS 0

Options +FollowSymLinks -MultiViews

ProxyPreserveHost On
ProxyPass / https://myproject.myname.rhcloud.com/
ProxyPassReverse / https://myproject.myname.rhcloud.com/

but I have the same error in my Apache logs: ProxyRequests not allowed here. Do you have an idea ?


Solution

  • A friend helped me to solve this problem:

    SetEnv PHP_VER 5_TEST
    SetEnv REGISTER_GLOBALS 0
    
    Options +FollowSymLinks -MultiViews
    
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteRule ^/?(.*)$ http://myproject-myname.rhcloud.com/$1 [L,P]
    

    This allows to have correct proxy to http://www.first-last.fr/myapp/ to http://myproject-myname.rhcloud.com/. Beware though, http://www.first-last.fr/myapp (without ending slash) does not work as a proxy and is converted to the "inner" site.