Bit of a head banger this one (for me at least), but from what I read I believe it’s possible with modrewrite. I’d be really grateful for some help as it’s a real blocker for me - I have had a tip off that I might need.
First what I’m trying to achieve, I hope this is clear…
should remain in the browser address bar as it is but serve the resource here…
base_url/properties/1
should remain in the browser address bar as it is but serve the resource here…
base_url/properties/2
and a catch all so that…
http://www.bar.co.uk/full_details
should remain in the browser address bar as it is but serve the resource here…
base_url/properties/2/full_details (or whatever’s put after the /2/)
Your first eight rows of low show that the redirection to properties/1/ was made. What’s the problem? Use an R=301,L to have that displayed to you (you can remove the R=301 when you go live with it).
That’s what I’ve called the “Missing Support Files” problem - see the tutorial in my signature for the two possible solutions.
Yes, but it looks like I’m conflicted over whether or not to include the leading / in the redirection. They should both be the same to please add (then test again) a / in front of properties in the FIRST RewriteRule.
Thanks very much for this. It certainly looks like you’ve got a handle on it - I’m trying it later today. Your initial understanding of my objective is correct, to reiterate…
The only thing I was surprised by in your example (code extract below) was the specific reference to “full_details” in the code. After the “/1/” or “/2/” I have many menu options including “photos”, “contact_us” etc, the usual suspects - thought taht it might be possible to trap the bit after the “/1/” and use it…If it’s necessary for me to verbosely and explicitly definine each “menu option” that’s ok but not as good I guess. Phew, it’s tricky to explain this stuff, hoping it’s clear.
RewriteCond %{HTTP_HOST} foo\\.co\\.uk [NC]
RewriteCond %{REQUEST_URI} !full_details
RewriteRule full_details/ properties/2/full_details [L]
# Note, there is NOTHING after full_details to to redirect to your "whatever"
Later today though, I’ll try your code and see where I get it. thanks.
Without the R=301 (or an external absolute redirection, i.e., http://yadda-yadda), the redirection should NOT be visible. Period.
Problem 1: Where did foo and bar go? It now looks like you’re dealing only with a single domain rather than co-located domains.
Problem 2: Where did properties/1 come from? I thought you were redirecting from domain/ to properties/1/ and that will NOT display properties/1 UNLESS you use an external redirection or 301.
Remember, I had you insert the 301 ONLY to verify that the redirection that you thought wasn’t working indeed was! Once confirmed, remove it and work on the missing support files, i.e., adding the <base> tag OR using absolute links.
Now, after all that, I have to apologize for not saying what had been on my mind in the first place: It’s MUCH easier to POINT a domain at the correct physical directory than to redirect (and retain the relative links, too). That goes back to your VirtualHost definitions which is where I recommend that you start (if at all possible).
Now that does make sense - I can see how that would be a more straightforward and maintainable solution. In this case though it wouldn’t work, this is a single Ruby on Rails application generating the specific “properties/1/” “properties/2/” links, as such there is only one physical directory. If I’ve undertood it correctly, I couldn’t do this and I need to rewrite. Keep thinking this is very close!
Specificity! Okay, full-details is not a specific code you’re using but a set of lowercase letters and underscores to match. Therefore, replace full_details in the regex with ([a-z_]+) and $1 in the redirection and that should do the trick for you. I.e.,
RewriteEngine on
RewriteCond %{HTTP_HOST} foo\\.co\\.uk [NC]
RewriteCond %{REQUEST_URI} !properties/1
RewriteRule (.*) properties/1/$1 [L]
RewriteCond %{HTTP_HOST} foo\\.co\\.uk [NC]
RewriteCond %{REQUEST_URI} !$1
RewriteRule ^([a-z_]+)$ properties/2/$1 [L]
# $1 in the RewriteCond is a forward "backreference"
# to the atom created in the RewriteRule
RewriteCond %{HTTP_HOST} bar\\.co\\.uk [NC]
RewriteCond %{REQUEST_URI} !(properties/2|properties/2/full_details)
RewriteRule ^([a-z_]+)$ properties/2/$1 [L]
That was likely my confusion over the full_details as I’d added a / after that in the regex. Please provide a test URI so I can tell what you’re after.
Now, after all that, I have to apologize for not saying what had been on my mind in the first place: It’s MUCH easier to POINT a domain at the correct physical directory than to redirect (and retain the relative links, too). That goes back to your VirtualHost definitions which is where I recommend that you start (if at all possible).
thanks - the logs show me that the / thing you did does solve the extra / problem - but damn and blast the thing still doesn’t work, browser renders a 400 Bad Request error “Bad Request Your browser sent a request that this server could not understand”…
Losing will to live - thanks for bearing with me - lost and unsure if this is fixable this way.
Problem #1 is that most people do not have access to the server/VirtualHost configuration files so my examples were for .htaccess (emphasis added to post #2). To change that code for use in the configuration files, you must add a / after the start anchor. Sorry for not stressing that earlier.
But it didn’t, actually generated an error message…
hmmmm…from the logs I think I was getting a double / on the end of the URI. I eliminated that but still not right, although i’m away from my test rig so can’t give the specfic result.
Now, it appears that you’ve set both domains to the same DocumentRoot. Therefore, mod_rewrite is your best option to control what happens to a request which must be dependent upon the host. Therefore …