Apache 2.4 whole URL rewrite https - apache

I have an Apache 2.4 configuration on my server, which is reached via the dns entries
alpha.site.com and beta.site.com
I want the alpha.site.com to redirect seamlessly to the document root /this
and beta.site.com to redirect seamlessly to the document root /that
I suspect that this is done by using the rewrite rules of Apache in httpd.conf,
eg something like this
RewriteEngine on
RewriteRule "^https:\/\/alpha\.site\.com$" "https://alpha.site.com/this" [PT]
which doesn't seem to work.
Are there any insights on how to make it work?

Ended up following a different route to solve this by using Alias directives, one for each URL.
<VirtualHost _default_:443>
ServerName alpha.site.com
Alias "/" "/this/"
</VirtualHost>
and
<VirtualHost _default_:443>
ServerName beta.site.com
Alias "/" "/that/"
</VirtualHost>

Related

Apache2 doesnt redirect non-www to www

I have a apache2 serving an application which works fine on www.domain.co.uk but when going to domain.co.uk (non www) it doesn't redirect the traffic. I added a redirect to my .conf file and it still doesn't work. See below:
<VirtualHost *:80>
ServerName domain.co.uk
Redirect permanent / http://www.domain.co.uk/
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain.co.uk
ServerAlias domain.co.uk
# Actual server configuration
</VirtualHost>
Does anyone know how to redirect the non-www traffic to www (or fix my configuration!)?
You have two separate areas of the configuration capturing domain.co.uk - one is in the redirection, the other (through your use of ServerAlias) in the configuration that serves the content. The second capture is overriding the first.
To resolve the issue, simply remove the line:
ServerAlias domain.co.uk
and restart Apache.

Using rewrite engine to route multiple domains to different paths on one server

I have two domains:
domain1.com
domain2.com
I have one Apache 2 server, with a document root /svr.
I want the following to occur:
domain1.com routes to the equivalent of /svr/examplepath/thisisadir/param/domain1
domain2.com routes to the equivalent of /svr/examplepath/thisisadir/param/domain2
I have tried using a .htaccess with RewriteEngine in /svr, using VirtualHost declarations in sites-available for each hostname and simply using 301 redirects. However, I can't use a simple 301, as the user should still see domain1.com in their browser.
I.e. domain1.com/about-this-site should map to /svr/examplepath/thisisadir/param/domain1/about-this-site.
I can't get RewriteEngine to route the hostnames to their respective endpoints, any advice would be much appreciated. I'm currently attempting to use HTTP_HOST in a .htaccess in the server root, but the rewrite rules still aren't taking effect.
Ilmiont
DocumentRoot directive sets the directory from which httpd will serve files and it is allowed in <VirtualHost> Context, so you can do something like this in your .conf files:
<VirtualHost *:80>
ServerName domain1.example.com
DocumentRoot /svr/examplepath/thisisadir/param/domain1
...
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.example.com
DocumentRoot /svr/examplepath/thisisadir/param/domain2
...
</VirtualHost>

How to correctly set Documentroot in Apache serving Plone

I have a Plone site called example.com located at /var/www/Plone (I think). I have the following settings for the site located in sites-available for vhosts (excerpt):
<VirtualHost 10.0.1.4:8082>
ServerAdmin webmaster#localhost
ServerName wiedhas.noip.me
DocumentRoot /var/www/Plone
When I try to reach my site wiedhas.noip.me, apache loads the Plone directory tree and not my Plone site. I can browse through the file system of /var/www/Plone but it is not loading the site. I must not have set the documentroot to the correct directory of my site? Any help much appreciated.
This an excellent docu about running plone behind apache and more.
http://docs.plone.org/manage/deploying/front-end/apache.html
A simple example with ssl, how a vhost could look like:
<VirtualHost $IP:80>
ServerName my.domain.com
Redirect / https://my.domain.com
</VirtualHost>
<VirtualHost $IP:443>
ServerName my.domain.com
ErrorLog logs/my.domain.com-http-error.log
CustomLog logs/my.domain.com-http-access.log combined
Include vhosts.d/....ssl.inc
RewriteEngine On
RewriteRule ^/(.*) http://127.0.0.1:$PORT_OF_PLONE/VirtualHostBase/https/%{SERVER_NAME}:%{SERVER_PORT}/zodb/path/top/plone/VirtualHostRoot/$1 [P,L]
</VirtualHost>
The most important part is the rewrite rule:
RewriteRule ^/(.*) http://127.0.0.1:$PORT_OF_PLONE/VirtualHostBase/https/%{SERVER_NAME}:%{SERVER_PORT}/zodb/path/top/plone/VirtualHostRoot/$1 [P,L]
$PORT_OF_PLONE = Port of your running plone instance
/zodb/path/top/plone = That's where you added the plone site in zope.
Took me a while to get mine going so maybe this helps:
My vhosts looks like this (where my plone site is called 'mywebsite'):
#---------------------------------
# www.mywebsite.com
#---------------------------------
<VirtualHost *:80>
ServerName www.mywebsite.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/(.*)$ http://127.0.0.1:8081/VirtualHostBase/http/%{SERVER_NAME}:80/mywebsite/VirtualHostRoot/$1 [L,P]
</IfModule>
</VirtualHost>
Hope that helps :)
As you see in the first and correct answer you do not need DocumentRoot. DocumentRoot points to a directory with files to render by Apache. But Plone brings it's own server, the Zope application server, which runs on a different port than Apache. The RewriteRule redirects the incoming request to the application server and modifies the response in a way that the redirection is hidden for the client.

How to do an Apache HTTP server virtual host blanket redirect with exceptions

I am running an Apache HTTP server that accepts requests for my domain. Lets call it www.mydomain.com. I have several sites that run under this domain and I have virtual hosts set up for each one that forwards the user depending upon with URL they use. Examples would be a.mydomain.com, b.mydomain.com, etc. I am aware that this may not have been the best way to accomplish this goal considering there are over 100 virtual hosts, but it is something I have inhertited and.. to put it short.. it works. Now on to my problem.
I have recently been tasked with shutting down most of the sites running under the domain. The sites that are shut down have been redirected to one page on my new domain (www.mynewdomain.com). What I have done is changed each of the virtual hosts from something like this:
<VirtualHost *:80>
ServerName a.mydomain.com
RewriteEngine On
RewriteRule ^/$ /SiteA [PT]
</VirtualHost>
to this:
<VirtualHost *:80>
ServerName a.mydomain.com
Redirect permanent / http://www.mynewdomain.com/replacement
</VirtualHost>
So now I have a list of 100 hosts that all redirect to the same place. What I need to know is if there exists a way to tell the system to redirect all sites at *.mydomain.com to my new page except certain ones. So some entry like this:
<VirtualHost *:80>
ServerName *.mydomain.com
Redirect permanent / http://www.mynewdomain.com/replacement
</VirtualHost>
<VirtualHost *:80>
ServerName h.mydomain.com
RewriteEngine On
RewriteRule ^/$ /SiteH [PT]
</VirtualHost>
<VirtualHost *:80>
ServerName v.mydomain.com
RewriteEngine On
RewriteRule ^/$ /SiteV [PT]
</VirtualHost>
Which means that every URL you see will go to "http://www.mynewdomain.com/replacement" except "h.mydomain.com" and "v.mydomain.com". The virtual hosts for "h" and "v" must still be intact because I have RewriteRules for each that must continue to work (additional rewriterules not seen in my examples).
Thanks in advance for the assistance!

add a server alias to the domain's VHOST?

I have a VPS. I hosted a domain ipointing to a sub directory of the www folder. The domain works fine till the home page. The moment I start going to other pages its shows my servers [orginalname]/[subdirectory name] . I think I need to add a server alias to the domain's VHOST. Can anyone tell me how to do that??
Are you using Apache?
Try with
<VirtualHost *:80>
DocumentRoot "/path/to/document/root"
ServerName name1
ServerAlias name2
...
I did it using the proxy Apache option, this is it:
My VirtualHost is http://dlx/ and I want to add an "alias" like http://dlx/drupal/
In the httpd.config file I added a proxy configuration:
<VirtualHost 127.0.0.1>
ServerName dlx
DocumentRoot "C:/deluxe/"
<LocationMatch /drupal/>
ProxyPass http://localhost/drupal/
ProxyPassReverse http://localhost/drupal/
</LocationMatch>
</VirtualHost>
Configure .htaccess on my dlx virtualhost (C:/deluxe/):
RewriteRule ^drupal/(.*)$ http://localhost/drupal/$1 [P,L]
That's it. It works for me, I hope it also works for you.