How to add a redirection for additional domain - apache2.2

I have a server with the following virtual host defined :
<VirtualHost *:80>
DocumentRoot /dev/null
ServerName www.originaldomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+\.)?originaldomain.com
ReWriteRule ^.*$ http://www.destinationdomain.com [L,QSA,R=301]
</VirtualHost>
This successfully redirects www.originaldomain.com and originaldomain.com to www.destinationdomain.com.
However I now to additionally redirect www.originaldomain2.com and originaldomain2.com to destinationdomain.com. As an Apache novice I am unsure how best to achieve this. Any advice appreciated.

Add a ServerAlias for each of your new domains.
ServerAlias www.originaldomain2.com
ServerAlias originaldomain2.com

Related

why my http redirect don't work with nagios?

I have a webserver with nagios, nagios is the only service working in this vm, so I want when I go to the root https://mymachine to redirect directly to https://mymachine/nagios.
I have made a configuration like this
<VirtualHost *:443>
ServerName mymachine.mydomain
ServerAdmin root#mymachine.mydomain
Redirect / https://mymachine.mydomain/nagios
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/nagios1.mymachine.mydomain.crt
SSLCertificateKeyFile /etc/pki/tls/private/nagios1mymachine.mydomain.key
SSLCACertificateFile /etc/pki/tls/certs/mymachine.mydomain.crt
</VirtualHost>
Restart http and..disaster! Firefox open the page
https://nagios1.mymachine.mydomain/nagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagiosnagios
and give the "redirect loop" error.
Consider I have also a redirect from http to https
active
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
If I remove it is the same thing.
Any solution?
Thanks
Solution found.
<VirtualHost *:80>
ServerName nagios1.mymachine.mydomain
ServerAdmin root#mymachine.mydomain
Redirect "/" "https://nagios1.mymachine.mydomain/nagios"
</VirtualHost>
<VirtualHost *:443>
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/nagios1.mymachine.mydomain.crt
SSLCertificateKeyFile /etc/pki/tls/private/nagios1mymachine.mydomain.key
SSLCACertificateFile /etc/pki/tls/certs/mymachine.mydomain.crt
</VirtualHost>

wildcard sub-domain on localhost using codeigniter

I have setup virtual host on my localhost by using codeigniter and it is working fine. But I am not able to create wildcard subdomains. To add virtual host below are my steps on windows machine.
C:\Windows\System32\drivers\etc\hosts.txt
In this host.txt I have added below line
127.0.0.1 localhost.com
I am using xampp .I have added below lines in httpd-vhosts.conf file.
D:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost localhost.com:80>
DocumentRoot "D:/xampp/htdocs/adeptra"
ServerName localhost.com
ServerAlias localhost.com
<Directory "D:/xampp/htdocs/adeptra">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/adeptra"
ServerName localhost.com
ServerAlias *.localhost.com
<Directory "D:/xampp/htdocs/adeptra">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
Below is my .htaccess code to remove index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
So now my question is, is it really possible to create wildcard subdomains in localhost? If yes, then please help me in this regard. Any help would be greatly appreciated.
A similar question has already been asked and answered here. Basically, no you cannot create subdomains on localhost. You need to create a local domain which is explained in the linked answer.

Rewriting rule from one subdomain to another subdomain

Please help me in rewriting Apache rule
I have a subdomain like subdomain.domain1.com/a/b/c.jpg
i want it to be like subdomain.domain2.com/a/b/c.jpg
Please how i can write
Thanks
According to the documentation you don't have to use it at all if you have access to the server configuration. If they were on the same box AND you can edit the VirtualHosts file, then you can do this:
<VirtualHost *:80>
ServerName subdomain.domain1.com
Redirect / http://subdomain.domain2.com/
</VirtualHost>
<VirtualHost *:80>
ServerName subdomain.domain2.com
</VirtualHost>
Otherwise you'll need to do this with mod_rewrite in .htaccess
RewriteEngine On
RewriteRule ^(.*)$ http://subdomain.domain2.com/$1 [R,L,QSA]

TYPO3 Frontend access on localhost (BE access working fine)

after successfully installing XAMP and then typo3 on my Mac, I set up a virtual host to avoid typing long URL when working on TYPO3.
I uncommented the http.conf line dealing with http-vhosts.conf so that I could set up virtual hosts, then I added my virtual host (called typo3dev) in httpd-vhosts.conf and I finally edited my hosts file accordingly.
So far so good, BUT now the issue that I'm having is that while pointing to the BE ( with http://typo3dev/typo3/ ) works just fine (I am able to log in and have fun in there), I cannot see the Frontend:
When pointing my browser to http://typo3dev/ , I get redirected to http://typo3dev/get-started/ where I get a Page Not Found error
Looking at the server error logs in I get that
$[Thu Jun 21 12:39:20 2012] [error] [client 127.0.0.1] File does not exist: /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1/get-started
By the way, my hosts file looks like this:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 typo3dev
my httpd-vhosts.conf like that:
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1"
ServerName typo3dev
</VirtualHost>
Thank you very much in advance for any help/ comment/ advice
Cheers
This looks like a RealURL/Apache configuration problem to me. Make sure that you allow .htaccess in your Apache configuration ...
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1"
ServerName typo3dev
<Directory /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1>
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
... or configure the RewriteRules directly in the VirtualHost section.
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1"
ServerName typo3dev
<Directory /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1>
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /Applications/XAMPP/htdocs/typo3/introductionpackage-4.7.1>
RewriteEngine On
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)$ - [L]
RewriteRule ^/(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</Directory>
</VirtualHost>
Remember to reload / restart Apache after making changes to the configuration.
It's seems to me like you have installed the wrong package. Install only the source package because all other package is for demo. Also if you can avoid Apache. It's complicated and bloated. I can recommend lighttpd. It's much easier to configure especially with virtual domains.

apache2 force proxy for specific url on a subdomain

I have a site that has dynamic virtual subdomains using mod_rewrite, as defined like this:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /var/www/example.com/www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.examle.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+)\.example.com(.*) /var/www/example.com/$1$2
</VirtualHost>
The problem is that I want a specific url, say subdomain.example.com/CONTROL/ to point back to www.example.com/ using a proxy (not url redirecting).
I have tried adding:
RewriteRule ^([^.]+)\.example.com/CONTROL(.*) /var/www/example.com/www$2 [P]
But that didn't work. Any ideas?

Resources