-1

I want all traffic to the non-https example.com and www.example.com to be redirected to the https www.example.com with the exception of a certain path, i.e. http://www.example.com/import , /import/XXX, /import/YYY should stay http.

At the moment, I'm using the following to redirect all non-https traffic to https.

<VirtualHost *:80>
        ServerName www.example.com

        Redirect permanent / https://www.example.com/
</VirtualHost>

Which I think is where most of my problems are coming from when I try and do rewrites as I end up in a loop.

Update

I've enabled mod_rewrite logging and got the result:

... (2) init rewrite engine with requested uri /import/batch_name
... (3) applying pattern '^(.*)$' to uri '/import/batch_name'
... (1) pass through /import/batch_name
... (3) [perdir /var/www/] add path info postfix: /var/www/import -> /var/www/import/batch_name
... (3) [perdir /var/www/] strip per-dir prefix: /var/www/import/batch_name -> import/batch_name
... (3) [perdir /var/www/] applying pattern '^' to uri 'import/batch_name'
... (3) [perdir /var/www/] add path info postfix: /var/www/import -> /var/www/import/batch_name
... (3) [perdir /var/www/] strip per-dir prefix: /var/www/import/batch_name -> import/batch_name
... (3) [perdir /var/www/] applying pattern '^' to uri 'import/batch_name'
... (3) [perdir /var/www/] add path info postfix: /var/www/import -> /var/www/import/batch_name
... (3) [perdir /var/www/] strip per-dir prefix: /var/www/import/batch_name -> import/batch_name
... (3) [perdir /var/www/] applying pattern '^' to uri 'import/batch_name'
... (3) [perdir /var/www/] add path info postfix: /var/www/import -> /var/www/import/batch_name
... (3) [perdir /var/www/] strip per-dir prefix: /var/www/import/batch_name -> import/batch_name
... (3) [perdir /var/www/] applying pattern '(^|/)\.' to uri 'import/batch_name'
... (3) [perdir /var/www/] add path info postfix: /var/www/import -> /var/www/import/batch_name
... (3) [perdir /var/www/] strip per-dir prefix: /var/www/import/batch_name -> import/batch_name
... (3) [perdir /var/www/] applying pattern '^' to uri 'import/batch_name'
... (2) [perdir /var/www/] rewrite 'import/batch_name' -> 'index.php'
... (3) [perdir /var/www/] add per-dir prefix: index.php -> /var/www/index.php
... (2) [perdir /var/www/] strip document_root prefix: /var/www/index.php -> /index.php
... (1) [perdir /var/www/] internal redirect with /index.php [INTERNAL REDIRECT]
... (2) init rewrite engine with requested uri /index.php
... (3) applying pattern '^(.*)$' to uri '/index.php'
... (2) rewrite '/index.php' -> 'https://www.example.com/index.php'
... (2) explicitly forcing redirect with https://www.example.com/index.php
... (1) escaping https://www.example.com/index.php for redirect
... (1) redirect to https://www.example.com/index.php [REDIRECT/301]
jamestsymp
  • 111
  • 2

1 Answers1

2

You can try Apache rewrite rules as below.

RewriteEngine On
RewriteCond %{REQUEST_URI}  !(import\/batch_name1|import\/batch_name2|import\/batch_name3) [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA]
Vaibhav Panmand
  • 959
  • 5
  • 17
  • The path in question is import/batch_name, so I've changed the folder1|folder2 etc to import/batch_name but that URL accessed through non-https is being redirected back to the https homepage of the site. – jamestsymp Oct 31 '14 at 15:06
  • @james.. I've updated URI_STRING as per your requirement – Vaibhav Panmand Oct 31 '14 at 17:34
  • Thanks, I hadn't escaped the forward slash but I still get redirected back to the homepage. I have updated the post with the log of mod_rewrite. The site itself is a Drupal site which may be complicating things with it's own rewrite rules. – jamestsymp Oct 31 '14 at 21:19