Forum Moderators: phranque
Ok rewriting http to https is normally pretty easy, but for some reason I cannot get this to work.
# redirect page to HTTPS should they be on the main site
# below line commented out as it is not needed in production yet, and
# affects testing.
##RewriteCond %{HTTP_HOST} ^(www\.)?some-domain\.com$ [NC]
### Following is due to server being behind load balancer
RewriteCond %{SERVER_PORT} 3187
RewriteCond %{HTTPS} off
RewriteRule ^some\-static\-page\.php$ [some-domain.com...]
Any help is appreciated.
The %{HTTPS} variable is not a native Apache variable, and may not be defined at the time that this code runs. Therefore, it is better to avoid using it if you can base the conditional redirect on %{SERVER_PORT} only or instead of %{HTTPS}.
Jim
RewriteRule ^([a-z]+)-([a-z]+)-([a-z]+)-([a-z]+)-([a-z]+)-([a-z]+)\.php$ [some-domain.com%{REQUEST_URI}...] [NE
,R=301,L,QSA]
Unless you can think of a better way to do this. Thanks for the guidance!
1) You do not need parentheses, unless you:
a) Want to create back-reference -or-
b) Want to apply a quantifier to a group of characters or a subpattern instead of just the one that precedes the quantifier.
2) [NE] should not be required here, unless there is something going on that I can't see.
3) [QSA] is not required, unless you wish to *append* additional query string parameters to those in the original request.
So, for the exact same URL-path format that your pattern addresses, I'd use:
RewriteRule ^(([a-z]+-){5}[a-z]+\.php)$ https://www.some-domain.com/$1 [R=301,L]