1

I have found similar questions, however no-matter what I try I am unable to get htaccess to do what I need it to. What I'd like is to direct visitors to an SSL connection when visiting one (or more) virtual subdirectories and then reverse this when they leave these selected subdirectories.

My rules look like this:

Options +FollowSymlinks
RewriteEngine on

#switch on SSL in /directory/ only
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/directory/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

#switch off SSL in other folders
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/directory/
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteRule ^([^/\.]+)/?$ /index.php?var1=$1 [NC,L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+).html /index.php?var1=$1&var2=$2 [NC,L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?var1=$1&var2=$2 [NC,L,QSA]

It seems that switching on SSL and switching off SSL conflict and when I try to access any page via https://www.domain.com/foo/ I am correctly redirected to http://www.domain.com/foo/.

However, when trying to access http://www.domain.com/directory/ (which should be SSL) I am redirected to http://www.domain.com/index.php?var1=directory and not https://www.domain.com/directory/.

I would really really appreciate a bit of guidance over where I'm going wrong. I've trawled through stackoverflow and the web for hours and hours looking for an answer but I'm just going round in circles and can't see the wood from the trees.

Thank you for any guidance/help you can offer.

BrochanGuMor
  • 710
  • 1
  • 9
  • 16
  • 1
    I may only suggest turning the rewrite debugging on (`RewriteLogLevel 9`) and check rewrite log, as your rules seems to be fine. To turn that logging on, you need to have access to server config + you will need to restart Apache for settings to become active. My only suggestion -- check the spelling -- most likely `^/directory/` or that part in the actual URL spelled wrongly (that is the only thing that I can make of these rules). It is also possible that you have some other rewrite/redirect rules elsewhere. – LazyOne Aug 31 '11 at 15:40
  • I've tried this but adding: RewriteLog "/var/log/apache2_rewrite.log" RewriteLogLevel 9 to the end of my httpd.conf file creates nothing in apache2_rewrite.log Also, I should stress that the spelling is OK.... any other ideas? – BrochanGuMor Aug 31 '11 at 17:46
  • Have you restarted Apache after making changes to a server config? Maybe (depends on your distro) you have edited the wrong config file? If all above is fine .. and you still see nothing in rewrite log, then no rewrite rules are getting executed -- something else redirects then. As long as you have at least 1 active rewrite rule (even if it does not do any rewrite -- does not match any URL) it WILL produce log entries. – LazyOne Aug 31 '11 at 18:05
  • Hi LazyOne, I've edited the correct file AFAIK and restarted apache but there is nothing showing up in the log. I think I'll implement a workaround in PHP until I can figure out how to get the log file working. Thanks for your help. – BrochanGuMor Aug 31 '11 at 18:14
  • @Studio4 - See [this question](http://stackoverflow.com/questions/10156093/mod-rewrite-with-external-redirect-and-internal-rewrite/10164349). `[L]` doesn't mean last in `.htaccess` files. – Adam M. Apr 24 '12 at 18:24

0 Answers0