Forum Moderators: phranque
I have setup 1 subdomain to redirect to my server. I'm calling it im calling my subdomain [music.example.com...] for this thread. I need people to reach a sub-folder in my server called "music" when they try to enter from [music.example.com...]
in other words, i want [music.example.com...] to view contents from:
[localhost...]
without including the "music" folder in the url
I have found 1 solution:
RewriteEngine on
RewriteCond %{HTTP_HOST} music\.example\.com
RewriteCond %{REQUEST_URI} !^/music
RewriteRule ^(.*)$ music/$1 [L]
the problem with this solution is that it will display a sub-dir path when someone is trying to browse further into the folder, example:
[music.example.com...]
will be displayed as
[music.example.com...]
but the desired result would be
[music.example.com...]
basically i need it to reach [localhost...] without viewing the directory "music" in the url.
anyone who could give any hints?
No actually, it won't. It's an internal rewrite, and therefore, does not "display" anything, nor does it cause the "display" of anything. It simply takes a request for the URL-path /xyx and prepends "/music" to the server filepath to be used to serve that URL-request.
So the subdirectory path is being exposed to the client as a URL by some other mechanism, and you'll have to find that 'actor' and correct its behavior to fix this problem. If your pages are generated by a script, then look at how the script 'builds' URLs for use in your on-page links. If the programmer referred to any filepaths then he should be found and punished, since only URL-paths should be referenced in building links...
Jim
all my scripts use relative paths, but links aren't the problem... the "problem" appears when one types this to the address bar:
[music.example.com...]
(changes into: [music.example.com...] , desired effect is [music.example.com...] )
basically i'd prefer it to exclude the "music" directory, even if someone manually enters the url to reach the "time" folder, or any other sub directory.
NOTE: this problem only appears when you try to reach folders, specifiying files works fine, example:
[music.example.com...] => [music.example.com...]
[music.example.com...] <=> [music.example.com...]
To change the address bar of the browser, the server must send a redirect status (with a new URL) in response to the current client-initiated HTTP request. This terminates the current HTTP request, and the browser will then (usually, and solely at its option) issue a second request, using the URL returned with the redirect response from the server. In doing so, it updates its own address bar to indicate "where it's going" and this is the action you are ascribing to the rule above. Unfortunately, since the rule is clearly coded as an internal URL-to-filepath rewrite, and not as an external URL-to-URL redirect, it is evident that it is NOT this rule that is directly causing the observed effect.
You need to be looking for other rules, mod_alias Redirect and/or RedirectMatch directives, or mod_negotiation rules, either in this .htaccess file, in another .htaccess file (higher or lower in the server filepath that is traversed when this URL is requested), in the server config file(s) (either hard-coded by your hosting company or 'written' there by your "control panel" script), or in one of your application scripts.
You can easily confirm this using the "Live HTTP Headers" add-on for Firefox/Mozilla-based browsers, and you will almost certainly see either a 301-Moved Permanently, a 302-Found, or a 303-See Other redirect response from your server. If it's not one of those, then it's likely going to be an error code, and this would imply an additional (and serious) problem with the way your server is configured to handle errors. However, no matter which of these redirect/error response codes you see, the next step is to hunt down the directive or script that is invoking this redirect, and to figure out why it decides to invoke a redirect when the /music subdirectory path is prepended to the server filepath.
Jim