本文介绍了Mod_rewrite http-> https重定向,除了一个URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我正在尝试这样做:

OK, so I'm trying to do this:

  • !www-> www
  • http-> https除了/[a-f0-9] {11}/

  • !www -> www
  • http -> httpsEXCEPT/[a-f0-9]{11}/

https://www.domain.com/[a-f0- 9] {11}/-> http://www.domain.com /[a-f0-9] {11}/

https://www.domain.com/[a-f0-9]{11}/ -> http://www.domain.com/[a-f0-9]{11}/

映射到控制器:index.php?(uri)例如/controller/action/id-> index.php/controller/action/id

map to controller: index.php?(uri)e.g. /controller/action/id -> index.php/controller/action/id

摘要:所有URL均应为 https://www.domain.com/(.*), /[a-f0-9] {11}/,应仅将其强制为http.

Summary: all URLs should be https://www.domain.com/(.*) except /[a-f0-9]{11}/, which should be forced to http only.

我有一套旧规则(见下文),看起来不太干净.我尝试将它们添加到帐户中以使其[/a-f0-9] {11}生效,并且最终重定向而不是重新映射,因此我最终访问了www.domain.com/index.php/thepattern0

I have an old set of rules (see below) which don't look very clean.I've tried adding to them to account for /[a-f0-9]{11} and it ends up redirecting instead of remapping, so I end up with www.domain.com/index.php/thepattern0

我如何清理这些规则并使其正常工作?

How do I clean these rules up and make this work?

<IfModule mod_rewrite.c>
    Options +FollowSymLinks -MultiViews -Indexes
    RewriteEngine On
    RewriteBase /
    #redirect to www
    RewriteCond %{HTTP_HOST} ^domain.com [NC]
    RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

    #redirect to https
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    #hide index.php
    RedirectMatch 404 .*php\.ini
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

推荐答案

您可以使用:

Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /

#redirect to www
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#redirect to https
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\s/+[a-f0-9]{11}[/?\s] [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]

#redirect to http
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} \s/+[a-f0-9]{11}[/?\s] [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]

#hide index.php
RewriteRule \.(?:php|ini)$ [L,R=404,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

这篇关于Mod_rewrite http-> https重定向,除了一个URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 05:48