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

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

Solution for Redirecting /internal/ Pages to HTTP (While Keeping Others on HTTPS)

Absolutely! You can adjust your .htaccess rules to make this happen—you just need to add an exception rule before your global HTTPS redirect, since Apache processes rewrite rules top-to-bottom. Here's how to modify your existing configuration:

Modified .htaccess Configuration

Options All -Indexes
Options +SymLinksIfOwnerMatch
RewriteEngine On

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

# Force HTTPS for all other requests (your original rule)
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Your existing content-handling rules (keep these as-is)
RewriteRule ^(.*)\.html $1\.php [L]
RedirectMatch ^/*$ https://mydomain_name/files/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /files/error.php [L]

Key Changes Explained

  • Rule Order Matters: The new /internal/ redirect rule comes first. When a user visits https://mydomain_name/internal/..., Apache matches this rule first, redirects them to HTTP, and stops processing further rules (thanks to the L flag).
  • Permanent vs Temporary Redirect: I used R=301 (permanent redirect) which is best for SEO and long-term changes. If you need a temporary redirect, swap it for R=302.
  • Cleaned Up Options: I grouped your Options directives at the top for better readability (Apache allows repeated Options but this is neater).
  • Preserved Your Existing Rules: All your original functionality (HTML-to-PHP conversion, root directory redirect, custom error page) remains intact—they just run after the redirect logic, which is the correct order.

Testing Tips

  • Clear your browser cache before testing, since 301 redirects are cached aggressively.
  • Test both scenarios:
    • Visit a non-internal page (e.g., http://mydomain_name/)—it should redirect to HTTPS.
    • Visit an internal page (e.g., https://mydomain_name/internal/test.php)—it should redirect to http://mydomain_name/internal/test.php.

内容的提问来源于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 08:01:13