Here is the folder layout.
/outside is not normally accessible anywhere on example.com
/public_html is the folder for http://example.com
How can I use Apache's htaccess to make the url http://example.com/outside/ to show content from the folder /outside?
Thanks!
How can I use Apache's htaccess to make the url http://example.com/outside/ to show content from the folder /outside?
You can't. As far as I have found out, Apache prevents directives in .htaccess files linking to locations outside the current web root.
You would have to do this in the central configuration:
Alias /outside /path/to/your/outside
You may be luckier with a symlink if you can turn FollowSymLinks on.
Related
How would I indicate Alias directives on shared hosting.
The file I want to serve is located:
home/user/public_html/the_file_I_want_to_serve.html
I would like to serve the file described above in:
home/user/desired_folder/subfolder1/subfolder2/HERE
I read the Apache's documentation on Alias directives, but I am unsure if I place directives in public_html/.htaccess or in desired_folder/.htaccess
Then I wonder, would directives in htaccess recognize a folder outside of its domain?
the url to load home/user/desired_folder/subfolder1/subfolder2/HERE is a subdomain like temp.domain.com which points to home/user/desired_folder/subfolder1/subfolder2
The Alias directive is not allowed outside of the server/vhost config. Since the htaccess file is a "per directory" context, there's no way to do anything outside of the context of the document root. Which means you can't do/know anything outside of the root (which I'm assuming is /home/user/public_html/. You'd have to move the "desired_folder" into the public_html directory, or at least symlink it from the public_html directory.
I have a web setup where there are multiple sites under one directory... and one media folder containing images for each site...
www.domain1.com/media/domain1.com/
www.domain2.com/media/domain2.com/
As you can see domain1.com's media can be accessed from domain2 e.g. www.domain2.com/media/domain1.com/
and vice versa...
I want to restrict domain1 to access /media/domain2.com/ folder can it be done via htaccess file?
my idea was to somehow read the domain name and match it with the directory its trying to access...
or
alternatively can redirect all requests in media folder to a php script that can do the matching...?
Use VirtualHost for each domain and specify DocumentRoot for them, it will also remove the /media/domainN/ from URL.
If you want to perserve the document root for some reason, try using this in each VirtualHost directive:
<Directory "full/path/to/media/domain1.com">
deny from all
</Directory>
and vice-versa for domain2.
My web root is /var/www/test/public, eg:http://www.test.local is rewrite to here,
but there's a folder /var/www/test/documents/ where I store some pictures to let others download. How can I config my apache rewrite mod to allow users to download pictures in this documents folder by a url?
Can anyone help me? Thanks!
You don't need mod_rewrite for that. You can use an Alias directive to map that images directory into your document root:
Alias /images /var/www/test/documents
^--web path ^---file system path
That'd make any request for example.com/images be internally redirected to /var/www/test/documents, even though that documents dir is not within your site's webroot.
Suppose I have a site example.com which points to the root directory of my hosting account and it has a .htaccess file in that directory. Say I have an other domain stuff.example.com which points to the same hosting account, but to a subdirectory of it, not to the root directory, and that subdirectory also has a .htaccess file in it.
If I visit stuff.example.com then will its .htaccess file be affected by the .htaccess settings of the root directory? Or htaccess search starts from the directory where the domain points to, so in this case the htaccess file in the parent directory is not taken into account?
Surprisingly the Apache docs don't ever explicitly answer this, as far as I can tell. But the htaccess tutorial gives the example that if a file is requested from /www/htdocs/example, then Apache looks for the following .htaccess files:
/.htaccess
/www/.htaccess
/www/htdocs/.htaccess
/www/htdocs/example/.htaccess
which presumably leads outside of the DocumentRoot. So it seems that the answer to your question is yes, Apache will read all .htaccess files all the way up to /.
will its .htaccess file be affected by the .htaccess settings of the root directory?
Yes. Where your web root is doesn't matter.
I have inherited a webserver already serving some websites. I am trying to migrate some of those sites to a new webserver.
One of those websites has a page called:
http://mydomain/ABCDepartment/
This URL also works:
http://mydomain/~joesmith
and the index page for joesmith actually lives in /var/www.../ABCDepartment/people/joesmith/
Now I am checking in httpd.conf and I see the following:
UseCanonicalName Off
UserDir public_html
UserDir disabled root
There are no special mod_rewrite rules for joesmith or the ~
How is this magic happening? UseCanonicalName is off, and if it wasn't UserDir public_html should look in /home/joesmith/public_html
What am I missing?
This is an Apache extension called userdir: http://httpd.apache.org/docs/1.3/mod/mod_userdir.html
It automatically rewrites requests to point to a folder called public_html within the user's home directory (the web server must have read access up the tree to this folder).