【问题标题】:How to make an exclusion for some url when redirectiong to https://www in .htaccess如何在.htaccess 中重定向到 https://www 时排除某些 url
【发布时间】:2015-12-04 04:30:21
【问题描述】:

我正在使用 .htaccess 将所有查询重定向到 https://www。例子.com

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

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.example.com%{REQUEST_URI} [L,R=301]

#and below some rules from symfony2 configuration

RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

RewriteRule .? %{ENV:BASE}/app.php [L]

现在我想排除一些 url:http://example.com/someurl (不要将此 url 重定向到 https 方案,也不要添加 www)我怎样才能得到这个?

我在 stackoverflow 中寻找答案,但在重定向到 https 时仅找到一条规则的解决方案...

【问题讨论】:

标签: .htaccess symfony mod-rewrite web https


【解决方案1】:

您可以使用RewriteCond 来使用排除项:

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/someurl [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{THE_REQUEST} !/someurl [NC]
RewriteRule textriteRule .* https://www.example.com%{REQUEST_URI} [L,R=301]

#and below some rules from symfony2 configuration

RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .? %{ENV:BASE}/app.php [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-10
    • 2012-12-23
    • 2016-09-01
    • 2018-07-03
    • 1970-01-01
    • 2022-01-11
    相关资源
    最近更新 更多