能否将网站含/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 matcheshttps://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=301is a permanent redirect (ideal for SEO and long-term caching). If you're testing changes, useR=302(temporary redirect) first to avoid browser caching issues, then switch to301once 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 tohttp://mydomain_name/internal/ - Visit any other page (e.g.,
http://mydomain_name/)—it should redirect to HTTPS as before
内容的提问来源于stack exchange,提问作者Wil67
相关产品推荐
相关产品推荐

