Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Server Operation

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 26th March 2012, 14:44
madsere madsere is offline
Junior Member
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Apache redirect to https/ssl using httpd.conf

I want to ensure that several variations of http://*.mydomain.*/* gets redirected to https://mydomain.com/*.

No problem, the following part of httpd.conf takes care of that:

Quote:
<Virtualhost 12.34.56.78:80>
ServerName www.mydomain.com
ServerAlias mydomain.co.uk
ServerAlias www.mydomain.co.uk
Redirect permanent / https://mydomain.com/
</VirtualHost>

<Virtualhost 12.34.56.78:443>
DocumentRoot /var/www/html/mydomain.com
ServerName mydomain.com
...
</VirtualHost>
So far so good - but I also want to make sure that any traffic to https://www.mydomain.com/* gets redirected to https://mydomain.com/* (partly to prevent certificate errors, partly to ensure Google only sees one website).

I can't add another Virtualhost container for this, Apache won't have that.

I can add a .htaccess file in the website, but that won't catch any links to subdirectories (i.e. https://www.mydomain.com/blah/ will not get caught unless I drop a .htaccess file in each and every directory, not an optimal solution).

How can I ensure traffic to https://www.mydomain.com/* gets redirected to https://mydomain.com/* ? I'm sure there must be a way to do this?
Reply With Quote
Sponsored Links
  #2  
Old 27th March 2012, 11:04
TiTex TiTex is offline
Senior Member
 
Join Date: Aug 2011
Location: Cluj-Napoca,Romania
Posts: 125
Thanks: 0
Thanked 18 Times in 17 Posts
Send a message via Skype™ to TiTex
Default

this should work with .htaccess

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domainname.tld$
RewriteRule ^(.*)$ https://domainname.tld/$1 [R=301]
</IfModule>
and you can remove this line from the VirtualHost directive
Quote:
Redirect permanent / https://mydomain.com/

Last edited by TiTex; 27th March 2012 at 11:09.
Reply With Quote
  #3  
Old 27th March 2012, 17:38
TiTex TiTex is offline
Senior Member
 
Join Date: Aug 2011
Location: Cluj-Napoca,Romania
Posts: 125
Thanks: 0
Thanked 18 Times in 17 Posts
Send a message via Skype™ to TiTex
Default

actually it does catch it , when somebody will try to access www.mydomain.com/blah/ he will be redirected to https://mydomain.com/blah/
isn't that what you want ?
Reply With Quote
  #4  
Old 27th March 2012, 20:16
madsere madsere is offline
Junior Member
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by TiTex View Post
actually it does catch it , when somebody will try to access www.mydomain.com/blah/ he will be redirected to https://mydomain.com/blah/
isn't that what you want ?
No, not unless you stick the .htaccess file into the /blah/ directory as well. Anyway, that functionality is already accomplished with the httpd.conf entry in my OP.

The problem is redirecting from https://www.mydomain.com/blah/ to https://mydomain.com/blah/

Last edited by madsere; 27th March 2012 at 20:19.
Reply With Quote
  #5  
Old 27th March 2012, 21:11
TiTex TiTex is offline
Senior Member
 
Join Date: Aug 2011
Location: Cluj-Napoca,Romania
Posts: 125
Thanks: 0
Thanked 18 Times in 17 Posts
Send a message via Skype™ to TiTex
 
Default

i looks like you don't wanna understand that what i've posted above does exactly that
it will redirect everything that's NOT https://mydomain.com/... to https://mydomain.com/...

and if you put a .htaccess file in you htdocs root folder all subfolders will inherit the settings in it if not otherwise specified in subfolders .htaccess as long as AllowOverride is enabled for the root folder.

do as you wish , i've just tested it on centos 5.6 with apache 2.4 and mod_rewrite enable... it does exactly what you asked for

Last edited by TiTex; 27th March 2012 at 21:18.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sessions not being saved gavimobile General 6 15th January 2012 15:05
trying to install roundcubemail ressel Installation/Configuration 13 24th December 2009 20:13
problems with suexec gobokster Installation/Configuration 7 7th May 2009 13:33
CENTOS 5 Ping Problem gAnDo Server Operation 11 28th March 2008 20:58
Problem with the installation of Dokeos (LMS) in ISPConfig jofranco General 4 28th April 2006 00:45


All times are GMT +2. The time now is 11:12.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.