1

I'm using the following TYPO3 mod-rewrite configuration (cleaned from not working attempts).

  • I want to exclude a specific URL from getting redirected to https.
  • Additionally add a rule for redirecting this url to http, if requested via https.

My errorcase is mostly to end up by getting redirected to index.php. Has anybody an idea?

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.de [NC]
    RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]

    RewriteRule ^fileadmin/(.*/)?_recycler_/ - [F]
    RewriteRule ^fileadmin/templates/.*(\.txt|\.ts)$ - [F]
    RewriteRule ^typo3conf/ext/[^/]+/Resources/Private/ - [F]

    RewriteRule ^(typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .* index.php [L]
</IfModule>

Attempt (not working):

Action application/x-httpd-php55 /cgi-sys/php55-fcgi-starter.fcgi
AddType application/x-httpd-php55 .php .php55

php_flag use_trans_sid Off
php_value date.timezone "Europe/Berlin"
php_value max_execution_time 600
php_value memory_limit 1024M


<FilesMatch "\.(js|css)$">
  <IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 7 days"
  </IfModule>
  FileETag MTime Size
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} ^/this_uri [NC]
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]

    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.de [NC]
    RewriteCond %{REQUEST_URI} !^/this_uri [NC]
    RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]

    RewriteRule ^fileadmin/(.*/)?_recycler_/ - [F]
    RewriteRule ^fileadmin/templates/.*(\.txt|\.ts)$ - [F]
    RewriteRule ^typo3conf/ext/[^/]+/Resources/Private/ - [F]

    RewriteRule ^(typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .* index.php [L]
</IfModule>

3 Answers3

1

The problem was, the following RewriteRule to index.php. The index.php was getting redirected to https each time it was requested via http. With the following line could solve the problem.

RewriteCond %{REQUEST_URI} !^/index.php [NC]
0

To exclude a spacific uri from https redirection, just put the following line above your https redirection Rule :

RewriteCond %{REQUEST_URI} !^/this_uri [NC]

And to redirect this_uri to http from https :

put the following 2 lines Bellow RewriteEngine directive in your htaccess :

RewriteCond %{HTTPS} on

RewriteCond %{REQUEST_URI} ^/this_uri [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
0

I was in the same situation, struggled for 4 hours and finally got my specific url to redirect to http

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/(home/panel/videos|user/profile) [NC] # Multiple urls
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /(home/panel/videos|user/profile) [NC] # Multiple urls
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

It worked for me :)

Khan Sharukh
  • 1,151
  • 12
  • 21