Jump to content
n1concepts

Force HTTPS & Also ReWrite Old files to New Ext in specific subfolder

Recommended Posts

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 by n1concepts

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 by n1concepts
Ensuring this post indicate problem solved - close post

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.