Help needed with mod_rewrite

Using a single web hosting account to host multiple sites

Help needed with mod_rewrite

Postby nickg35 » Wed Feb 11, 2009 6:44 am

Hi,

I'm new to the forum and mod_rewrite. I was hoping someone could help me out with this problem I can't figure out. First, a little background about the current rewrite rules setup:

The main site's subfolders are rewritten to subdomains as follows:

website.example.com --> www.example.com/website.

The server is a Windows Apache 2.0 with mod_ssl. The Rewrite rules are located in httpd.conf and ssl.conf configuration files. Here is an example rewrite, and how the config files look like:

httpd.conf:

RewriteEngine On

RewriteRule ^/website(.*)$ https://www.example.com/website/ [NC,R,L]

This command redirects any request that contains "website" to SSL. Then the internal rewrite occurs within ssl.conf:

ssl.conf:

RewriteEngine On

RewriteRule ^/website(.*)$ http://website.example.com/website/$1 [NC,P]
ProxyPassReverse /Website/ http://website.example.com/website/

RewriteRule ^/$ http://www.example.com/ [R,L]

SSLEngine on
<Location />
SSLRequire (%{SSL_CIPHER_USEKEYSIZE} >= 128)
</Location>

This works great, except if I have a website that sits at the root web, folders within the subdomain are not rewritten. For example, instead of

www.example.com/website/Login.asp

I get

www.example.com/Login.asp

which of course leads to invalid pages. I am suspecting that there are relative paths on the site itself preventing it from staying nested under the subfolder. Is there a workaround for this? Using this strategy we have only been able to publish sites that are nested under subwebs. Is there a better way to go about it?

Many thanks,
Nick
nickg35
 
Posts: 4
Joined: Wed Feb 11, 2009 5:54 am

Postby richardk » Wed Feb 11, 2009 10:23 am

If it is relative paths: FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken.

Why are you using mod_rewrite instead of just mod_proxy
Code: Select all
Redirect 302 /website https://www.example.com/website

and
Code: Select all
ProxyPass        /website/ http://website.example.com/website/
ProxyPassReverse /website/ http://website.example.com/website/

RedirectMatch 302 ^/$ http://www.example.com/

SSLEngine On
<Location />
  SSLRequire (%{SSL_CIPHER_USEKEYSIZE} >= 128)
</Location>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nickg35 » Thu Feb 12, 2009 1:26 pm

Thanks for the reply. Perhaps I need to provide some more info about the site itself. I can't make any changes to it, since it was designed by a 3rd party vendor. Part of the problem I think is that it has to stay at the root web, meaning I can't nest it under say, website.example.com/example. The problem is whether I go with mod_rewrite or mod_proxy, the subfolders links are broken. This is what I've figured out so far:

When I hit website.example.com, I get the login page. If I look at the properties, the URL is http://website.example.com/Login/Login.asp. What it does is it hits the default.asp URL which contains the following:

"<frame name="fm_MainApp" target="main" src="/Login/Login.asp" marginwidth="0" marginheight="0"
scrolling="no" noresize>"

This is an internal redirection that directs the visitor to this page.

The main webserver, which hosts http://www.example.com, knows nothing about that redirection. As a result, the following Rewriterule throws an error:

RewriteRule ^/Website(.*)$ http://website.example.com/$1 [NC,P]
ProxyPassReverse /Website/ http://website.example.com/

But if I change /Login/Login.asp to Login/Login.asp, it loads the page fine, except all the other folders in the site are not rewritten. For instance instead of

www.example.com/website/images

I get

www.example.com/images

I hope this gives a better picture of what I'm trying to accomplish. Is there a way to adapt the URLs on the server side without making changes to the site?

Thanks again.
nickg35
 
Posts: 4
Joined: Wed Feb 11, 2009 5:54 am

Postby richardk » Sun Feb 15, 2009 11:06 am

Are the links relative?

When I hit website.example.com, I get the login page. If I look at the properties, the URL is http://website.example.com/Login/Login.asp. What it does is it hits the default.asp URL which contains the following:

"<frame name="fm_MainApp" target="main" src="/Login/Login.asp" marginwidth="0" marginheight="0"
scrolling="no" noresize>"

This is an internal redirection that directs the visitor to this page.

The main webserver, which hosts http://www.example.com, knows nothing about that redirection. As a result, the following Rewriterule throws an error:

RewriteRule ^/Website(.*)$ http://website.example.com/$1 [NC,P]
ProxyPassReverse /Website/ http://website.example.com/

But if I change /Login/Login.asp to Login/Login.asp, it loads the page fine, except all the other folders in the site are not rewritten.

Shouldn't it be /website/login...? The frame should not affect the links in the page.

Is there a way to adapt the URLs on the server side without making changes to the site?

Not with mod_rewrite or mod_proxy. There is an unofficial module though.

Why don't you just redirect to the sub domain?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nickg35 » Wed Feb 18, 2009 9:27 am

Since the site needs to be accessed externally, the only other option would be to publish the site directly. This is definitely a possibility, except I would like to keep things consistent and use mod_rewrite if at all possible.

The only way the links don't break is by doing a rewrite rule and ProxyPassReverse for each sudomain site folder in ssl.conf. Unfortunately since the sub site sits on IIS, I can't use .htaccess. So right now it looks like this:

RewriteRule ^/website(.*)$ http://website.example.com/website/$1 [NC,P]
ProxyPassReverse /website/ http://website.example.com/

RewriteRule ^/AdvCondition(.*)$ http://website.example.com/AdvCondition/$1 [NC,P]
ProxyPassReverse /AdvCondition/ http://website.example.com/

RewriteRule ^/Login(.*)$ http://website.example.com/Login/$1 [NC,P]
ProxyPassReverse /Login/ http://website.example.com/

...and so forth for about 20+ subdirectories. The problem with doing this is if there is another subdomain that needs to request ^/css for instance, this will break for the other site.

Since the site itself cannot be modified, I am trying to see if there is any other workaround.

Thanks,
Nick
nickg35
 
Posts: 4
Joined: Wed Feb 11, 2009 5:54 am

Postby richardk » Wed Feb 18, 2009 10:51 am

The problem with doing this is if there is another subdomain that needs to request ^/css for instance, this will break for the other site.

I'm not quite sure what you mean by this.

Instead of
Code: Select all
RewriteRule ^/website(.*)$ http://website.example.com/website/$1 [NC,P]
RewriteRule ^/AdvCondition(.*)$ http://website.example.com/AdvCondition/$1 [NC,P]
RewriteRule ^/Login(.*)$ http://website.example.com/Login/$1 [NC,P]

couldn't you use
Code: Select all
ProxyPassMatch ^/(website|AdvCondition|Login)(/(.*))?$ http://website.example.com/$3
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nickg35 » Wed Feb 18, 2009 12:36 pm

There are many subdomains that are served via our main website, using rewrite rules and reverse proxy. If a subweb is using absolute paths, the only way to prevent it from hitting the root of the web is to do a rewrite for each of its subfolders. The problem is, if there are multiple webs that happen to have the same subfolder names, then this may not be the best strategy.

I tried the ProxyPassMatch command and got back an "invalid command". mod_proxy on the server is enabled.

I will be calling the website vendor and ask them if there is a chance they can provide a relative links version of the site or a patch so rewriting can work.

Thanks for all your help.
nickg35
 
Posts: 4
Joined: Wed Feb 11, 2009 5:54 am

Postby richardk » Thu Feb 19, 2009 7:11 am

The problem is, if there are multiple webs that happen to have the same subfolder names, then this may not be the best strategy.

I can't think of any reliable way to fix that problem without removing the absolute paths.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 3 guests

cron