How to setup a dynamic apache webroot based on url - apache

In my setup i have an apache/php website named test.com and two subfolders, apples.html and oranges.php
So my file system structure is basically this:
html/folder1/apples.html
html/folder1/.htaccess
html/folder2/oranges.php
html/folder2/.htaccess
The problem is that i have a unique domain https://applesandoranges.com and changes needs to do the following:
each request sent to https://applesandoranges.com should be routed to apples.html (a static html app with a specific .htaccess file)
each request sent to https://applesandoranges.com/oranges should be routed to oranges.php that contains a php based web application (with a specific .htaccess file).
Is there a way to this with apache?
i was checking this https://httpd.apache.org/docs/2.4/vhosts/mass.html. but i'm not sure on how to do the setup.

Related

IIS 8.5 Redirecting

I have a basic project running on IIS 8.5
sites
-> test.domain.com
--->virtualPath
----->index.html
On the browser when enter https://test.domain.com/virtualpath, it is return 301 (redirect) to test.domain.com/virtualpath/
I don't have any URL Rewrites in IIS configuration. Just trying to figure out why it is redirecting to test.domain.com/virtualpath/
How can avoid this 301 redirect?
The short answer is that IIS doesn't handle extensionless URLs very well. URLs are processed based on the file extension, otherwise it's presumed to be a directory you're looking to get served. The normal convention however is to omit the index.html file.
But most services like IIS take that for granted, and if nothing is specified, it will lookup if there's a /index.html.
Lets take a simple example:
google.com
In reality what's being served to you is:
google.com/index.html
Lets take your request as an example https://test.domain.com/virtualpath
test.domain.com
- virtualPath/
- index.html
As you can see, you're essentially trying to get a directory rather than a specific file. It's up to IIS to try to find and understand that you want a file instead of a directory now. That's why you're getting a 301. It's redirecting you to the /index.html file.

Mapping folder to different folder on the same Apache Server

I have My old domain on my server myexample.com with folder name "myexample" and a have different domain mymaindomain.com, What i am looking is whenever user opens mymaindomain.com/contest it opens the site that is in "myexample" folder and still keep the url in address bar mymaindomain.com/contest/whatever.xxx using htaccess or httpd on apache server.
Put
Alias /contest /public_html/myexample
in the virtual host definition for myexample.com. Note though, that this may cause links in your content to be wrong if they expect to be located at / instead of at /contest.

Zend sub-folder as DocumentRoot for sub-domain gives invalid controller thinking folder name is a controller

I have a zend project located in the /account sub folder. I want to be able to create sub-domain virtual hosts and point their DocumentRoot to this sub folder
In index.php I have this line that sets the URL of the zend project folder
define('SiteUrlUser','http://'.$_SERVER['HTTP_HOST'].'/account/');
The DocumentRoot setup for one sub-domain is
DocumentRoot /var/www/account
As i'm browsing the site at subomdain.domain.com it always adds /account to the URLs which is normal but then throws this error
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (account)'
Now if I remove /account from any URL while accessing the site through a subdomain the pages render just fine. So basically www.domain.com/account/something.html in a subdomain would be subdomain.domain.com/something.html which is working perfectly fine.
I'm planning to setup the server so that all users will login through their sub-domain. The zend folder will be put on it's own server and used as the DocumentRoot for all sub-domains so what would I change in the index.php to make this work?
Thanks
I wouldnt nest the project inside another non-zend project, i would give it its own root out side the web accessible dir of the other project and point the subdomain there. Then just make your module/controller for account the default via routing.
However if you do nest them then you will have to set the baseUrl
If the parent project is also a zend app then i would merge the two together and use routing to handle the sub-dir mapping this way you can do a wildcard vhost and point them all to the same application instance on the filesystem.

How to force apache only to serve a single file?

My site uses nginx. I use apache only for large file uploading to the server. I have a script upload.php which I POST the files to via a flash uploader script.
Apache runs on a subdomain, so I post files to upload.domain.com/upload.php
Is there any way to prevent apache from serving the actual site on that subdomain? ideally I want to post files to upload.subdomain.com and have it be directed to upload.php on that subdomain
I mean I could setup a different document root for apache and thats it, but are there any other ways?
If I understand correctly you want all requests to upload.domain.com to be directed to upload.php? A RewriteRule inside the VirtualHost that catches all requests should work:
RewriteEngine On
RewriteRule . /full/path/to/upload.php

Tomcat serving URLs wrong with mod_proxy and apache

I've set up a host with apache to serve static pages and to use Tomcat to serve my web application (See this question). The static pages are server from
"http://myhost.com"
and the dynamic (tomcat) pages are server from
"http://myhost.com/myapp"
The mod_proxy makes sure the "http://myhost.com/myapp" are forwarded to tomcat server running on "http://myhost.com:8080".
The problem is that now you get the standard Tomcat introduction page on "http://myhost.com/myapp" but if you click on a local link (e.g. 'Status') on the left, it generates an URL
"http://myhost.com/manager/status" while it should generate: "http://myhost.com/myapp/manager/status"
(The same is true for webapps installed under tomcat)
What should be changed in my configuration (apache, tomcat?) to redirect my tomcat links to the right place?
Have you set the ProxyPassReverse setting in your httpd.conf. This will overwrite the HTTP Header an you'll get to the correct request on the side of tomcat.
Your URLs are mapped from:
http://myhost.com/myapp -> http://myhost.com:8080
This means that accessing the above URL will be mapped to the ROOT application in Tomcat. The ROOT application will generate pages that contain links from Tomcat's root context.
In other words, if you go to:
http://myhost.com:8080
you will get a page that contains links to
http://myhost.com:8080/manager/status
This link will work. However when that page is given back to a browser that requested it via Apache, the full URL then looks like: http://myhost.com/manager/status
I assume that you intend to deploy an application called 'myapp' to Tomcat? If that is the case the Tomcat URL for this app will be
http://myhost.com:8080/myapp
Which will also work be mapped correctly when accessed via Apache.
If you absolutely must access Tomcats root application in this way you'll have to rewrite the URLs it outputs in the pages it returns.
I've had the most success with mod_proxy_ajp. It requires mod_proxy, but works over ajp. Using it instead, your conf file looks similar
ProxyPass / ajp://localhost:8009/
See my similar question and also the answer to this question. The only fault in mod_proxy_ajp that I've found is that if I need to restart tomcat I have to force an apache restart too.