n1concepts Posted October 27, 2018 Share Posted October 27, 2018 (edited) Hi, I'm starting a rebuild on an existing website & need to 'force' HTTPS to a subfolder entitled, 'dev' along with redirect specific 'HTML' files to their (new) 'PHP' extensions. FYI: only queries to that subfolder should be of focus of this particular .htaccess file - i.e. path/dev/.htaccess I have an .htaccess file defined in the 'dev' subfolder with the below content & that's forcing HTTP to HTTPS (see that code below) RewriteEngine on RewriteCond %{HTTPS} off RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^(.*)$ https://%{HTTP_HOST}/dev/$1 [R=301,L] # The remaining, below, rules are to map old (HTML) file names to their (new) php file names found in 'dev' folder RewriteRule ^contact-us.html$ contact-us.php [L] RewriteRule ^register.html$ register.php [L] RewriteRule ^welcome.html$ welcome.php [L] RewriteRule ^log-in.html$ log-in.php [L] RewriteRule ^log-out.html$ log-out.php [L] RewriteRule ^my-account.html$ my-account.php [L] Note: I know there is one, immediate, error (L flag stopping the remaining Rewrites from firing, right?) However, before I make any more edits, I thought best to ask (here) to get someone's insight on how to accomplish the following: 1st, i need to enforce HTTP to HTTPS for all content going to that subfolder - i.e. http://domain/dev or http://domain/contact-us.html, etc... - and that appears to be working based on the 1st 'ReWrite' rule. However, I think that rule is the problem so asking: Q1: should I remove the L flag & will that allow the remaining rules to parse to see if a match? Q2: if answer to 1st question, No, then please advise how best to modify the .htaccess file, specifically, for the 'dev' subfolder which is where that .htaccess file reside (there are others in / and other subfolders which should remain 'as is'. Appreciate the input in advance. Craig Edited October 27, 2018 by n1concepts Quote Link to comment https://forums.phpfreaks.com/topic/307820-force-https-also-rewrite-old-files-to-new-ext-in-specific-subfolder/ Share on other sites More sharing options...
requinix Posted October 27, 2018 Share Posted October 27, 2018 First things first: do you actually have a problem? Does this not all work the way you want? If so, what is it doing and what do you want it to be doing? Because if you don't have a problem then... there is no problem. Quote Link to comment https://forums.phpfreaks.com/topic/307820-force-https-also-rewrite-old-files-to-new-ext-in-specific-subfolder/#findComment-1561778 Share on other sites More sharing options...
n1concepts Posted October 27, 2018 Author Share Posted October 27, 2018 (edited) Yes, there was a problem - i stated the objectives but think those issues wasn't understood (no worries & thanks for replying, anyway). To that, I went ahead & applied the changes that I thought would correct this issues to produce the, expected, results (and indeed that fixed the issues). I just removed the L flag on the 1st Rewrite rule to allow the remaining rules to be parsed for a match, then i added that 1st rule again, at the very end of the script with the L flag to stop processing should NO match found from previous rules. Results? working 100% now - thx again but not sure (again) anyway for response (problem fixed - My post was just to validate that I thought would fix the issue). PROBLEM SOLVED - thx! BTW: I like your post / reply... Edited October 27, 2018 by n1concepts Ensuring this post indicate problem solved - close post Quote Link to comment https://forums.phpfreaks.com/topic/307820-force-https-also-rewrite-old-files-to-new-ext-in-specific-subfolder/#findComment-1561779 Share on other sites More sharing options...
requinix Posted October 27, 2018 Share Posted October 27, 2018 Something to keep in mind with the L flag: it doesn't stop all rewriting, only the current round of it. If you change the request then Apache will start another round of rewriting when it works on the new path. I asked if there was a problem because I wasn't seeing one. With what you originally had, the first RewriteRule would redirect the user to the HTTPS page - and external redirects should just about always have a [L] because they're redirects and you won't want to do anything more with it. When the request comes back to the server (over HTTPS this time) the later RewriteRules will kick in, and they should work normally. All told, unless I'm missing something (and it sounds like I might be) then what you posted should have worked fine. Quote Link to comment https://forums.phpfreaks.com/topic/307820-force-https-also-rewrite-old-files-to-new-ext-in-specific-subfolder/#findComment-1561780 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.