Compute Engine Custom domain accessibility - apache

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

Related

Alias Directive for shared hosting

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.

htaccess restrict folder access based on domain

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.

Change Domain VirtualHost paths in Plesk (Apache)

I have a domain that'll be using Zend Framework and I need to modify the documentroot for this particular domain to resolve to Zend's path.
Anyone know how to update the virtualhost on a particular domain?
Typically, you don't have to modify the document root.
Put your application files one level above your document root, and put the contents of the zend public folder in whatever your document root is (e.g. public_html or htdocs).

How do I set the local document root in Apache?

So this is my directory structure
/
/test
index.php
blah.php
blah.php
So in /test/index.php I have a link such as this
Link
but I want it to link to /test/blah.php, not the blah.php in the root directory. Basically, I want to set a local document root. Is this possible to set this using .htaccess or in the httpd.conf?
If an a tag on /test/index.php has its href set to /blah.php, then it's the browser that's interpreting that as pointing to a file in the document root. So you can't achieve what you want without changing the way you're generating the href attribute.
You have a couple of options for this:
You can omit the forward slash to generate links relative to the current URL instead of the document root. A link in /test/index.php pointing to blah.php will be interpreted as /test/blah.php.
You can write some custom code to generate your links. You could have a function my_special_link ($link) that takes in blah.php and prepends the current file's directory, for example.
Add this to your httpd.conf or better yet put it in a virtualhost directory
NameVirtualHost *:80
<VirtualHost *:80>
ServerName blah.localhost
DocumentRoot C:\web\test
</VirtualHost>
In WINDOWS\System\system32\etc\bin or somewhere ( LOOK for 'hosts' file ), edit hosts file so it has
127.0.0.1 blah.localhost
Restart apache and go to blah.localhost in the browser.

Magic Apache redirecting for /~username

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).