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.
Related
I have a Google Compute Engine instance(installed apache, php, mysql etc.) and a custom domain name. I can do add my Custom Domain to my Google Compute Engine.
Lets my domain name be www.try.com .
my instance's "www" folder;
--->try
--->somethingelse2
--->somethingelse3
..
How can I set "www.try.com" access to only "try" folder? Thanks.
In deciding what file to serve for a given request, httpd's default behavior is to take the URL-Path for the request (the part of the URL following the hostname and port) and add it to the end of the DocumentRoot specified in your configuration files. Therefore, the files and directories underneath the DocumentRoot make up the basic document tree which will be visible from the web.
If a directory is requested (i.e. a path ending with /), the file served from that directory is defined by the DirectoryIndex directive. For example, if DocumentRoot were set as above, and you were to set:
DirectoryIndex index.html index.php
You only need to modify the path in the Directory index.
You can find more information here
Given the directory www/html/file.php would it be it be appropriate to place my .htaccess alongside with file.php?
That way making rules for file.php (demo example below)
~Rule~ file.php ...
file.php would be located.
No. It depends on the setting of AllowOverride for specific directories - however, in most configurations AllowOverride is enabled for the document root.
See http://httpd.apache.org/docs/current/de/howto/htaccess.html#page-header
According to that documentation, you should put any rules into the global configuration file instead of .htaccess files if possible. if you can't access the global configuration file, you should put the .htaccess file into the folder it applies to.
In the directory /var/www I have the following directories: foo, bar and baz. I want foo to be my document root, that is, when www.example.com/ is requested, the directory /var/www/foo is served. Otherwise, for all other directories, /var/www/ is considered to be document root, so www.example.com/bar/ serves /var/www/bar/ and www.example.com/baz/ shows /var/www/baz.
I could set the document root to /var/www/foo/ and move the directories bar and baz there, which I don't want to do. The server has a main purpose and a few other, unrelated tasks which are contained in these additional directories. I don't want to mix this.
I can set the document root to /var/www/foo and use the Alias directive to map the other directories to the required locations, so in the case above
Alias /bar /var/www/bar
Alias /baz /var/www/baz
However, each time that I add another directory, I would have to modify the apache configuration.
Is there a better way?
Is it possible to disable lookup for .htaccess file in subdirectories, when I know I will only need my .htaccess in root directory?
I know it can be done with "AllowOverride None" when you have access to the server configuration file. But can I do this with my .htaccess file in root as well?
No. It must be done inside a <Directory> directive, which can only exist inside core configuration files.
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.