Using apache 2, I have a simple virtual host container:
<VirtualHost 127.0.0.1>
ServerName developmentServer
DocumentRoot /var/www
</VirtualHost>
The site is accessible, but I'm having trouble using root relative links within the site. I have an 'images' folder that is located at the root level. When I am within a folder or subfolder, I want to specify an image path that is root relative. (And actually all paths will be root relative regardless of the page depth.) This currently is not working:
<img src="/images/file.jpg">
But this will:
<img src="../images/file.jpg">
I understand the difference, but I do not know what needs to be changed in Apache to allow me start all links with a "/" so they are root-relative. I'm thinking there is a configuration setting, and I shouldn't have to rely on mod_rewrite. Any suggestions?
Is the image located at /var/www/images/file.jpg and are you accessing the page containing this image over HTTP (http://developmentServer/...)? Then it must work.
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
I am running XAMPP 1.8.2
Inside of htdocs folder I have a several sites.
Now I downloaded a working website from my hosting/server and found out that the identical copy of that website run on Xampp [http://localhost/mysite] can not find the images.
It is looking for images on
[http://localhost/img/myimage01.jpg] instead of
[http://localhost/mysite/img/myimage01.jpg]
I read some solutions but they all come to pointing the whole thing to [http://localhost/mydomain]
I would prefer if I can tell XAMPP to look for files for every domain from it's own root directory.
How can I do this?
Thanks
The easiest way is to create separate virtual host for each site folder in /htdocs
So you will access the http://mysite.local instead http:// localhost/mysite
There are two things to do:
1. edit C:\xampp\apache\conf\extra\httpd-vhosts.conf (by default) adding something like
<VirtualHost *:80>
ServerName mysite.local
DocumentRoot C:/XAMPP/htdocs/mysite
</VirtualHost>
2. edit c:\windows\system32\drivers\etc\hosts adding
127.0.0.1 mysite.local
restart xampp and try http://mysite.local
You generally can't move a whole website from http://<somedomain> to http://<somedomain>/<somefolder>. Things are bound to go wrong with links between pages in the site and links within pages to images.
Let's say you are displaying images within HTML web pages using image tags like this:
<img src="img/myimage01.jpg"></img>
This will probably work as the browser will look for the img folder in the same folder as the web-page.
On the other hand if your image tag looks like this (note the extra /) you will have the problem you describe:
<img src="/img/myimage01.jpg"></img>
The extra / means the browser will look for the img folder at the root of the domain.
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.
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.
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).