Forum Moderators: phranque
I'm using a domain where the web root (a CMS system) is in a subdirectory, drupal. I want for users when they type in the url www.myurl.com that it goes to www.myurl.com/drupal to show them the information without showing the redirect, i.e., the address bar is still at www.domain.com. I've modified the following code from another post to do this:
# Rewrite index.htm OR index.html OR / to /anydir/index.htm
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule ^(index\.php?)?$ /drupal/index.php [L]
# I thought this would do it, but it makes the server crap out with a 500 error
# RewriteCond %{REQUEST_URI}!^/survey/
RewriteRule ^(.*)$ /drupal/$1 [L]
And it works wonderfully. the problem is when I'm trying to access another subdirectory under the root, say, [domain.com...] I believe the above rules redirect this, also, to www.domain.com/drupal/survey, where I'm told the page doesn't exist (which it doesn't).
What would I need to do to make this work properly? Hope that explanation made sense...
Welcome to WebmasterWorld!
The key is to use RewriteCond to make the rewrite (this is not an external redirect, it's an internal "silent" rewrite) conditional, like the line you've got commented-out:
# RewriteCond %{REQUEST_URI} !^/survey/
So, you'll need to generalize that so that only requests for pages in the root directory are rewritten to /drupal. You also need to do this to avoid rewriting requests for /drupal to /drupal/drupal, etc. which would cause an "infinite" loop.
# Rewrite requests for root directory resources to /drupal subdirectory
RewriteCond %{REQUEST_URI} !^/.+/
RewriteRule (.*) /drupal/$1 [L]
This may make more sense if you realize that once mod_rewrite rules are applied, the server re-preocesses all config directives in the new URL-path, so that rewrites and access restrictions that apply to that new path can be applied. This is needed to avoid user-created security holes. This makes mod_rewrite appear to act recursively. Because of this, you have to make sure the code is written to avoid rewriting /drupal to /drupal/drupal, etc. The single RewriteCond above solves both problems.
Jim
What do you all think?
[edited by: jdMorgan at 5:22 pm (utc) on Sep. 1, 2005]
[edit reason] No URLs, please. See TOS. [/edit]
You asked how to avoid rewriting anything that is in a subdirectory, and so that's what the code I posted does. The nature of rewriting is that the definition of what is to be rewritten and/or what is not to be rewritten must needs be precise -- No wiggle-room whatsoever.
As it stands, the URLs for all resources accessed by your drupal pages need to "appear" to be in root, otherwise they will not be rewritten.
You may want to consider different ways of organizing this, such as a list of pages and directories that *do* need to be rewritten to /drupal, or alternately, a list of pages and directories that should not be rewritten. It is also possible to combine the two, as long as the resulting specification is complete and concise.
Jim