能否将网站含/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 visitshttps://mydomain_name/internal/..., Apache matches this rule first, redirects them to HTTP, and stops processing further rules (thanks to theLflag). - 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 forR=302. - Cleaned Up Options: I grouped your
Optionsdirectives at the top for better readability (Apache allows repeatedOptionsbut 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 tohttp://mydomain_name/internal/test.php.
- Visit a non-internal page (e.g.,
内容的提问来源于stack exchange,提问作者Wil67
相关产品推荐
相关产品推荐

