You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否将网站含/internal/路径的HTTPS页面重定向至HTTP?

How to Redirect /internal/ Paths to HTTP While Keeping Others on HTTPS

Absolutely, you can set up this exception with a small tweak to your .htaccess file. The key is to add a rule that handles the /internal/ path before your global HTTPS redirect runs—Apache processes rewrite rules top-to-bottom, so we need to catch those requests first. Here's how to adjust your configuration:

Modified .htaccess Configuration

Options All -Indexes
RewriteEngine On

# New rule: Redirect HTTPS requests for /internal/ paths to HTTP
RewriteCond %{HTTPS} on
RewriteRule ^internal/(.*)$ http://%{HTTP_HOST}/internal/$1 [R=301,L]

# Your existing rules follow below
RewriteRule ^(.*)\.html $1\.php [L]
RedirectMatch ^/*$ https://mydomain_name/files/index.php
Options +SymLinksIfOwnerMatch
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /files/error.php [L]

# Global HTTPS redirect for all other paths
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Key Details to Note

  • Rule Priority: The new /internal/ redirect is placed first because Apache executes rules in order. When a request matches https://mydomain_name/internal/..., this rule triggers, redirects to HTTP, and the [L] flag stops further rule processing—so the global HTTPS redirect never applies to these paths.
  • Redirect Type: R=301 is a permanent redirect (ideal for SEO and long-term caching). If you're testing changes, use R=302 (temporary redirect) first to avoid browser caching issues, then switch to 301 once everything works as expected.
  • Original Behavior Preserved: All non-/internal/ HTTP requests will still be redirected to HTTPS just like your original configuration intended.

Testing Steps

After updating your .htaccess, clear your browser cache (to bypass old cached redirects) and verify both scenarios:

  • Visit https://mydomain_name/internal/—it should automatically redirect to http://mydomain_name/internal/
  • Visit any other page (e.g., http://mydomain_name/)—it should redirect to HTTPS as before

内容的提问来源于stack exchange,提问作者Wil67

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:54:41