Beta version of site via mod_rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

Beta version of site via mod_rewrite

Postby imforumman » Tue Apr 19, 2005 7:26 am

I have two sub-domains pointing at the same directory.

When requesting a file via the "www" subdomain it should just deliver it.

When requesting a file via the "beta" subdomain it should check to see if the file exists at "/~beta/", and use that if it exists. Otherwise it should serve the same file as if it had been accessed via "www".

This must be done in such a way that if "beta.domain.net/path/file.html" exists (meaning "www.domain.net/~beta/path/file.html" exists) but a css file requested via relative paths used by that html file, does not exist, then it defaults back to the "www" version.

I can point the subdomain anywhere you want me to, speak I can point it at "/~beta/" if you that makes more sense.

Now my first crack at this looked like this:
Code: Select all
RewriteBase /
RewriteCond %{HTTP_HOST} ^beta.* # if on beta
RewriteCond /~beta%{REQUEST_FILENAME} -s # andif file exists in beta dir
RewriteRule ^(.*) /~beta$1 # rewrite!

or
Code: Select all
RewriteBase /
RewriteCond %{HTTP_HOST} ^beta.* # if on beta
RewriteRule ^(.*) /~beta$1 # rewrite!
RewriteCond %{REQUEST_FILENAME} !-s # if file does not exist
RewriteRule ^/~beta(.*) $1 # rewrite back

neither works at all. Please help me!

Thank you very much!
imforumman
 
Posts: 1
Joined: Tue Apr 19, 2005 6:23 am

Postby HM » Sun Apr 24, 2005 5:25 am

Check that HTTP_HOST is right. I have a feeling it may be different from the Host: header the visitor requested something like server.yourwebhost.com try %{HTTP:Host}
HM
 

Postby Guest » Sun Apr 24, 2005 5:29 am

This might work

Code: Select all
RewriteBase /
RewriteCond %{HTTP:Host} ^beta\. # if on beta
RewriteCond %{DOCUMENT_ROOT}/~beta%{REQUEST_URI} -s # and if file exists in beta dir
RewriteRule ^ /~beta$1 # rewrite!
Guest
 

Postby Caterham » Sun Apr 24, 2005 1:54 pm

This might work


%{DOCUMENT_ROOT} contains /var/www/htdocs
%{REQUEST_URI} contains /var/www/htdocs/requested.php

If not (%{REQUEST_URI} contains only requested.php), there is an error in the server configuration.

BTW: Comments are not allowed this way, they must be in a separate line (otherwise you get a 500 internal server error)
Code: Select all
# comment
RewriteRule ....
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby HM » Mon Apr 25, 2005 11:46 am

Caterham wrote:
This might work

%{REQUEST_URI} contains /var/www/htdocs/requested.php


Isn't that REQUEST_FILENAME. REQUEST_URI is supposed to contain basically what the visitor sent in the "GET <uri> HTTP/1.1" header.
HM
 

Postby Caterham » Thu Apr 28, 2005 4:02 am

yes, sorry I ment request_filename, which was used in posting #1;

according to a posting on modrewrite.de, the problem is now solved.
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 62 guests

cron