I have the below redirect set in httpd.conf which redirects subdomain.domain.com to domain.com/topics/apps
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [OR]<br>
RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com.gov$<br>
RewriteRule ^/(.*)$ http://www.domain.com/topics/apps[R=301]
But if i try the same with https, it wont redirect to that page but shows domain.com homepage (not redirect). I guess this is because the DNS entry for subdomain.domain.com is also having the same IP as domain.com.
Can you guys suggest fixing this https redirect to http://domain.com/topics/apps.
Thanks,
Sudeer.
You need to set up a Virtual Host on Port 443 and also set it to Named Virtual Hosts when the IP is the same but the names are different.
NameVirtualHost *:443
<VirtualHost *:443>
ServerName myserver.de
RewriteEngine On
RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 0
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com.gov$
RewriteRule ^/(.*)$ http://www.domain.com/topics/apps[R=301]
</VirtualHost>
My experience is that Apache, by default, handles SSL with a separate VirtualHost on a different port. Look for the VirtualHost which is listening on 443 and set the redirection there.
Do you have access to the Vhosts ? If so, I would skip the rewrites and simply do this(and restart httpd):
<VirtualHost *:443>
ServerName subdomain.domain.com
ServerAdmin you#you.com
DocumentRoot this/needs/to/exist
Redirect permanent / http://domain.com/topics/apps
</VirtualHost>
Related
Please take a look at my .conf file. I am trying to redirect people visiting my site on https to http as I need to sort some other stuff before I can renew the SSL cert so for the time being need to redirect all visitors to http://
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/myproject
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
ServerAlias example.com
// method 1 - Not working
RedirectMatch permanent ^(.*)$ http://www.example.com$1
// method 2 - Not working
Redirect / http://www.example.com/
// method 3 - Not working
RewriteEngine On
RewriteCond %{HTTPS} On
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
// method 4 - Not working
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1
DocumentRoot /var/www/myproject
</VirtualHost>
I have got ProxyPass set up in the apache server config.
PHP seems cant detect the HTTPS.
How do i detect the HTTPS in PHP or redirect if not HTTPS in .htaccess?
Apache config:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName domain.co.uk
ServerAlias www.domain.co.uk
ProxyPass / http://external-domain.com/
Include /etc/letsencrypt/options-ssl-apache.conf
...
</VirtualHost>
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Source: https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
This will check in PHP if you're on HTTPS.
if(!empty($_SERVER["HTTPS"])) {
}
I would like to know if is possible to keep all the site under ssl except two sub folders that works as a endpoint for external calls with apache.
I've my site (www.example.com) that user can see only trought https and I would like to keep example.com/subfolder1 and example.com/subfolder2 reachable also trough the normal http protocol. Is it possibile?
This is the .conf file of apache.
<VirtualHost 127.0.0.1:8080>
ServerName example.com
ServerAlias www.example.com
Redirect / https://www.example.com/
</VirtualHost>
I'm trying to avoid the use of the .htaccess file, is it possibile? Thanks to all!
You could use a Rewrite (instead of a Redirect) so you can set a condition. Maybe like this:
<VirtualHost 127.0.0.1:8080>
ServerName example.com
ServerAlias www.example.com
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(subfolder1|subfolder2)/? [NC]
RewriteRule ^(.*) https://www.example.com%{REQUEST_URI} [R,L]
</VirtualHost>
You have to enable the rewrite module for that too:
LoadModule rewrite_module modules/mod_rewrite.so
I've set up my own server.
Let's say my main server folder is /home/www and I've set the nameservers so that all domains point to this location.
Now, here's what I want to do :
Have each domain's files in a separate subfolder
Based on the domain requested, silently redirect to the appropriate subfolder
E.g.
if we need somedomain.com or www.somedomain.com or www.somedomain.com/anything/ (or any such variation for that matter) redirect the request from /home/www/ to /home/www/somedomain.com/
How can this be done?
And here's what I've tried (but given that .htaccess is definitely ... not my thing, it'll most likely be close to non-sensical...) :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?somedomain.com$ [NC]
RewriteRule ^(/)?$ somedomain.com [L]
There are two possible choices. you can create Virtual Host for each domain and set virtual document root.
Or
You can use rewrite rule.
From apache Virtual host documentation:
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/www.example1.com
ServerName www.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/www.example2.org
ServerName www.example2.org
# Other directives here
</VirtualHost>
You can find out more in http://httpd.apache.org/docs/2.2/vhosts/examples.html
I recently switched from a shared hosting to a VPS.
Everything is working fine and I can access al of my domains.
But I seem to have 1 problem:
In the past all non-www url's where redirected to url's with www.
I did this with the following htaccess.txt code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.tx3\.be$ [NC]
RewriteRule ^(.*)$ http://www.tx3.be/$1 [R=301,L]
But I'm using a new htaccess at the time with the following code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^off(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
But both are not working on redirecting my non-www domain.
When I visit my non-www domain, I get the following page:
"Apache is functioning normally"
I tried using the DirectAdmin redirect for redirecting the non-www domain to a domain with www, but that also didn't work.
Maybe I've got it all wrong and it wasn't a htaccess problem in the first place.
Did I forget something in my server settings?
I don't know, everything looks to be in order.
(I did double check my DNS settings and they appear to be fine)
Does anyone know what I should be doing next?
Please try this
Rewriteengine on
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
If using windows download putty (ssh client) give it your servers ip address select type as ssh and click open.
It'll ask you for a username and password give it your root username and password (should have been provided by vps hosting company)
Now cd through to your apache config folder (I'm only familiar with debian based setups if you're using a redhat based setup you may have to google correct path) /etc/apache2/sites-available
Now look at the directory listings (ls) and it'll show you the apache configs available chances are you'll have something like www.tx3.be in there. Edit that file I recommend using pico or nano by doing pico
Here's an example off my server
root#hinch:/home/hinch# cd /etc/apache2/sites-available
root#hinch:/etc/apache2/sites-available# ls
default
default-ssl
root#hinch:/etc/apache2/sites-available# pico default
Now you're in your apache config file you'll see something like this
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin root#yourdomain.com
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm default.htm default.html default.php
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
After the line that says ServerAdmin add in the following
ServerAlias tx3.be
ServerAlias www.tx3.be
Save the file and restart apache
service apache2 restart or service httpd restart
Delete all redirect code from your .htaccess and make sure you have both the www. dns A record and the #. A record pointing to your servers ip address. Now regardless of which version of the domain the user goes to they'll see your site.