I have one host for two domain. The first domain and its rules (aaaaa.com) are working.
When I try to append rules of second one (bbbbb.com) send an Internal Error 500 message.
The goal is bbbbb.com should reply the content of bbbbb directory. Please help..
Options -Indexes
<IfModule mod_rewrite.c>
ErrorDocument 404 /errors/error404.html
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^((?!www\.)(?!aaaaa\.com)[^\.]+)\.
RewriteRule ^(.*)$ aaaaa/index.html?p=%1 [L]
RewriteCond %{HTTP_HOST} ^bbbbb\.com [NC]
RewriteRule ^(.*)$ bbbbb/%1 [R,L]
</IfModule>
If you have access to the apache configuration, I recommend you to use Virtual Hosts to achieve your purpose.
You should include this configuration in your /etc/apache2.conf file:
<VirtualHost *:80>
DocumentRoot "/www/aaaaa"
ServerName aaaaa.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/bbbbb"
ServerName bbbbb.com
</VirtualHost>
Supposing that your web directories are stored in /www.
You can find the documentation here:
https://httpd.apache.org/docs/current/vhosts/
Related
I have read quite a few postings on configuring SSL on Xampp/Windows/Apache/VirtualHost and think I have done it right, but when I enter in the virtualhost url (q.localhost), I always get to the default localhost Xampp info page, which reads: 'http://q.localhost/xampp/' in the url bar.
Below are what I have in my various files that I think are relevant:
Apache httpd.conf:
LoadModule ssl_module modules/mod_ssl.so
Apache httpd-vhosts.conf:
<Directory C:/vhost>
AllowOverride All
Require all granted
</Directory>
#this is the default address of XAMPP
<VirtualHost *:80>
DocumentRoot "C:/XAMPP/htdocs/"
ServerName localhost
</VirtualHost>
#this is the first vhost address in XAMPP
<VirtualHost *:443>
DocumentRoot "C:/XAMPP/htdocs/data/anycompany"
ServerName q.localhost
<Directory "C:/XAMPP/htdocs/data/anycompany">
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
SSLEngine On
SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"
</VirtualHost>
###### THIS WORKS, BUT COMMENTED OUT REPLACED BY THE ABOVE ########
#this is the first vhost address in XAMPP
#<VirtualHost *:80>
# DocumentRoot "C:/XAMPP/htdocs/data/anycompany"
# ServerName q.localhost
#</VirtualHost>
Windows Hosts file:
127.0.0.1 localhost
127.0.0.1 q.localhost
127.0.0.1 test.localhost
Apache httpd-ssl.conf:
DocumentRoot "C:/xampp/htdocs/data/anycompany"
ServerName q.localhost:443
ServerAdmin admin#localhost.com
Apache version 1.8.3 being used.
Doesn't seem to have any error message in the apache error log.
SOLVED:
Seems like the configuration above was correct, but I didn't realize one thing, and I had to include some further configuration to make it work. Explained below:
Typing "q.localhost" in URL window failed, and redirected to the Xampp default page. Had to include https:// before the url, so typing in "https://q.localhost" brought up the correct page. However, clicking on the various other links on the website also failed, as it required, but did not have the "https://..." in front of the link.
To correct the above problem, I referred to this article. which suggested adding redirects to configuration file: \xampp\apache\conf\extra\httpd-xampp.conf. I added what he suggested to enable automatic redirects without having to always type in "https://..."
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect /xampp folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} xampp
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /phpMyAdmin folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} phpmyadmin
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /security folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} security
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /webalizer folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} webalizer
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
# Redirect /folder_name folder to https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} folder_name
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]
</IfModule>
I have a server with two subdomains, so I set up redirection for both of my subdomains specially because I want to force that the two subdomains are accessed only by https instead of http. My ideal scenario would be that I have those redirection untouched and be able to access phpMyAdmin locally (for security reasons obviously) but the problem now is that when I type the following in my browser:
127.0.0.1/phpmyadmin or localhost/phpmyadmin it takes me to https://example1.com/webservice/myrestfile-REST.php?appconfig=example
Is there any way to solve this problem?
This is the configuration that I currently have with the redirection:
<VirtualHost *:80>
ServerName example1.com
ServerAlias API.com
ErrorLog /var/www/html/error.log
CustomLog /var/www/html/requests.log combined
DocumentRoot /var/www/html
RewriteEngine On
LogLevel alert rewrite:trace6
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^ https://example1.com/webservice/myrestfile-REST.php?appconfig=example [R,L]
Redirect permanent / https://example1.com
# RewriteRule ^(.*)$ /webservice/myrestfile-REST.php?appconfig=example [QSA,L]
</VirtualHost>
<VirtualHost *:443>
ServerName example1.com
DocumentRoot /var/www/html
RewriteEngine On
RewriteRule ^(.*)$ /webservice/myrestfile-REST.php?appconfig=example [QSA,L]
SSLEngine On
SSLCertificateFile /etc/httpd/ssl/40d5d69ae6a53.crt
SSLCertificateKeyFile /etc/httpd/ssl/sitekey.key
SSLCertificateChainFile /etc/httpd/ssl/gd_bundle-g2-g1.crt
</VirtualHost>
It looks like you have apache set to listen on any ip <VirtualHost *:80> which would include the loopback address 127.0.0.1. See if you can just use the condition to ignore those.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/phpmyadmin$ [NC]
RewriteCond %{HTTP_HOST} !^127\.0\.0\.1 [OR]
RewriteCond %{HTTP_HOST} !^localhost [NC]
RewriteRule ^(.*)$ /webservice/myrestfile-REST.php?appconfig=example [QSA,L]
See how that works and let me know.
If I put theese lines to .htaccess everything works well (when I'm going to http://www.example.ru I'm redirected to http://example.ru).
RewriteEngine On
# Installation directory
RewriteBase /
# Redirect all www to non-www
RewriteCond %{HTTP_HOST} ^www.example.ru [NC]
RewriteRule ^(.*)$ http://example.ru/$1 [L,R]
But If I put exactly same lines to <VirtualHost> -> <Directory> section trying to go to http://www.example.ru redirects me to http://example.ru/www.
Anybody knows why?
UPD
New VirtualHost:
<VirtualHost *:80>
ServerName example.ru
ServerAlias www.example.ru
ServerAdmin webmaster#localhost
DocumentRoot /home/example/www/example.ru/www
RewriteEngine On
<Directory /home/example/www/example.ru>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/example/www/example.ru/log/error.log
LogLevel warn
SetEnvIf Remote_Addr 127.0.0.1 loopback
CustomLog /home/example/www/example.ru/log/access.log combined env=!loopback
# Redirect all www to non-www
RewriteCond %{HTTP_HOST} ^www.example.ru [NC]
RewriteRule ^(.*)$ http://example.ru$1 [L,R]
</VirtualHost>
Spent some time I've figured out, that in VirtualHost section, pattern will match against the part of the URL after the hostname and port, and before the query string (in my case "/").
In Directory section, pattern will match against the filesystem path.
I have virtual hosts
<VirtualHost 10.10.10.10:80>
ServerAdmin webmaster#server.com
ServerName server.com
ServerAlias subdomain-a.server.com subdomain-b.server.com subdomain-c.server.com subdomain-d.server.com
DocumentRoot /srv/www/server.com/public_html/
</VirtualHost>
<VirtualHost 10.10.10.10:443>
ServerAdmin webmaster#server.com
ServerName server.com
ServerAlias subdomain-a.server.com subdomain-b.server.com subdomain-c.server.com subdomain-d.server.com
DocumentRoot /srv/www/server.com/public_html/
</VirtualHost>
I want to force visitors use https for subdomain-a and subdomain-c. Visitors of subdomain-b and subdomain-d could use http and https. How to configure .htaccess?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(subdomain-a|subdomain-c)\.server\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I've got a VirtualHost directive in /etc/apache2/openpanel.d/www.example.com.conf:
<VirtualHost *:80>
ServerAdmin "jon#example.com"
DocumentRoot /home/openpanel-admin/sites/www.example.com/public_html
ServerName www.example.com
ServerAlias example.com
<Directory /home/openpanel-admin/sites/www.example.com/public_html>
AllowOverride All
Allow from all
</Directory>
Include /etc/apache2/openpanel.d//www.example.com.inc/[^.#]*
Include /etc/apache2/openpanel.d//global.inc
</VirtualHost>
And I've the following in /etc/apache2/openpanel.d/www.example.com.inc/RewriteRules
<Directory /home/openpanel-admin/sites/www.stallfinder.com/public_html>
Options +FollowSymlinks
RewriteEngine On
RewriteRule agricultural-show-c780.html /search/event/agricultural-shows/1/ [R=301,L]
RewriteRule antique-fair-c596.html /search/event/antique-and-collectors-fairs/1/ [R=301,L]
RewriteRule baby-and-toddler-fairs-c896.html /search/event/baby-and-toddler-fairs/1/ [R=301,L]
RewriteRule book-fair-c631.html /search/event/book-fairs/1/ [R=301,L]
# etc... there are ~3000 of these
</Directory>
And I've got an .htaccess file in /home/openpanel-admin/sites/www.example.com/public_html:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# Search pages
RewriteRule ^search/(stallholder|event)/?$ /find-$1.php [L]
RewriteRule ^search/(stallholder|event)/([^/]+)/([0-9]+)/? /$1.php?name=$2&id=$3 [L]
But the RewriteRules in the include file (RewriteRules) don't appear to be parsed/used.
The file is being included because I can put non-allowed stuff in there and apache will fail to load the config file, but if I turn on Apache redirect logging, then I only see [perdir] lines as if all the RewriteRules I've got in the RewriteRules include aren't being processed.
The global.inc file is empty, and the RewriteRules in my .htaccess file work fine.
Any clue what I'm doing wrong?
Try adding RewriteOptions directive into your .htaccess to allow executing rewrite rules on parent (upper) level.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteoptions