从HTTPS重定向中排除特定URL

时间:2016-02-24 09:49:17

标签: apache .htaccess mod-rewrite https typo3

我正在使用以下TYPO3 mod-rewrite配置(从不工作尝试中清除)。

  • 我想将特定网址排除在重定向到https。
  • 此外,如果通过https请求,请添加一个将此网址重定向到http的规则。

我的错误用例主要是通过重定向到index.php来结束。有人有想法吗?

<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>

尝试(不工作):

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 个答案:

答案 0 :(得分:1)

问题是,以下RewriteRule为index.php。每次通过http请求时,index.php都会被重定向到https。 使用以下行可以解决问题。

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

答案 1 :(得分:0)

要从https重定向中排除空间uri,只需将以下行放在https重定向规则上方:

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

并将this_uri从https:

重定向到http

在你的htaccess中添加以下2行Bellow RewriteEngine指令:

RewriteCond %{HTTPS} on

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

答案 2 :(得分:0)

我遇到了同样的情况,挣扎了 4 个小时,终于让我的特定 url 重定向到 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]

它对我有用:)