Is it possible to do a wildcard HTTP->HTTPS redirect for all vhosts?Redirect, Change URLs or Redirect HTTP...
What are these green text/line displays shown during the livestream of Crew Dragon's approach to dock with the ISS?
Can I become debt free or should I file for bankruptcy? How do I manage my debt and finances?
g++ and clang++ different behaviour with recursive initialization of a static member
Why is this code uniquely decodable?
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
How to add multiple differently colored borders around a node?
Do my Windows system binaries contain sensitive information?
How would we write a misogynistic character without offending people?
Distance Puzzle
How to deny access to SQL Server to certain login over SSMS, but allow over .Net SqlClient Data Provider
How to approximate rolls for potions of healing using only d6's?
What am I? I am in theaters and computer programs
Inventor that creates machine that grabs man from future
What is a term for a function that when called repeatedly, has the same effect as calling once?
What to do when being responsible for data protection in your lab, yet advice is ignored?
How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?
awk unexpectedly removes dot from string
Are small insurances worth it
If a druid in Wild Shape swallows a creature whole, then turns back to her normal form, what happens?
Find the next monthly expiration date
How to avoid being sexist when trying to employ someone to function in a very sexist environment?
Book where the good guy lives backwards through time and the bad guy lives forward
How to mitigate "bandwagon attacking" from players?
Creating a wave of string in Javascript
Is it possible to do a wildcard HTTP->HTTPS redirect for all vhosts?
Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to AskIn Nginx, how can I rewrite all http requests to https while maintaining sub-domain?Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to AskCan't redirect https for httpApache Webserver Modifying Config or Re-direct has no effectApache/Tomcat Webserver using AJP Proxy - How to rewrite/redirect URLApache (http) behind load balancer (http/https) - Redirect does not preserve httpsHTTP to HTTPS redirect failingApache how to prevent access on https and http without a matching domainApache https to http redirectuse VirtualHost *:443 as default for all unmatched ServerAlias
On our dev server we have multiple sites for multiple developers running via vhosts in Apache 2.4.6. We are on CentOS 7.
We want to redirect all http://www.site.ext.dev-username.commondomain.ext to https://www.site.ext.dev-username.commondomain.ext. Here, dev-username and site.ext can change depending on dev site and user.
We have previously used something like this:
<VirtualHost *:80>
ServerName www.site.ext.dev-username.commondomain.ext
Redirect permanent / https://www.site.ext.dev-username.commondomain.ext/
</VirtualHost>
But is it possible to match any (or at least wildcard) ServerName and redirect accordingly, i.e. with a backreference to a regex? Maybe with a DirectoryMatch or something instead of the vhost?
I have noticed this in the documentation (for directory and location matching), which is sadly not compatible with my version of Apache:
From 2.4.8 onwards, named groups and backreferences are captured and written to the environment with the corresponding name prefixed with "MATCH_" and in upper case. This allows elements of URLs to be referenced from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.
centos apache-2.4 redirect
add a comment |
On our dev server we have multiple sites for multiple developers running via vhosts in Apache 2.4.6. We are on CentOS 7.
We want to redirect all http://www.site.ext.dev-username.commondomain.ext to https://www.site.ext.dev-username.commondomain.ext. Here, dev-username and site.ext can change depending on dev site and user.
We have previously used something like this:
<VirtualHost *:80>
ServerName www.site.ext.dev-username.commondomain.ext
Redirect permanent / https://www.site.ext.dev-username.commondomain.ext/
</VirtualHost>
But is it possible to match any (or at least wildcard) ServerName and redirect accordingly, i.e. with a backreference to a regex? Maybe with a DirectoryMatch or something instead of the vhost?
I have noticed this in the documentation (for directory and location matching), which is sadly not compatible with my version of Apache:
From 2.4.8 onwards, named groups and backreferences are captured and written to the environment with the corresponding name prefixed with "MATCH_" and in upper case. This allows elements of URLs to be referenced from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.
centos apache-2.4 redirect
Possible duplicate of Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask
– Gerald Schneider
6 hours ago
I don't think it is.
– Leonard Challis
5 hours ago
I agree - this question is about how theServerNameandServerAliasdirective works in apache, rather than how mod_rewrite works.
– Jenny D
2 hours ago
add a comment |
On our dev server we have multiple sites for multiple developers running via vhosts in Apache 2.4.6. We are on CentOS 7.
We want to redirect all http://www.site.ext.dev-username.commondomain.ext to https://www.site.ext.dev-username.commondomain.ext. Here, dev-username and site.ext can change depending on dev site and user.
We have previously used something like this:
<VirtualHost *:80>
ServerName www.site.ext.dev-username.commondomain.ext
Redirect permanent / https://www.site.ext.dev-username.commondomain.ext/
</VirtualHost>
But is it possible to match any (or at least wildcard) ServerName and redirect accordingly, i.e. with a backreference to a regex? Maybe with a DirectoryMatch or something instead of the vhost?
I have noticed this in the documentation (for directory and location matching), which is sadly not compatible with my version of Apache:
From 2.4.8 onwards, named groups and backreferences are captured and written to the environment with the corresponding name prefixed with "MATCH_" and in upper case. This allows elements of URLs to be referenced from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.
centos apache-2.4 redirect
On our dev server we have multiple sites for multiple developers running via vhosts in Apache 2.4.6. We are on CentOS 7.
We want to redirect all http://www.site.ext.dev-username.commondomain.ext to https://www.site.ext.dev-username.commondomain.ext. Here, dev-username and site.ext can change depending on dev site and user.
We have previously used something like this:
<VirtualHost *:80>
ServerName www.site.ext.dev-username.commondomain.ext
Redirect permanent / https://www.site.ext.dev-username.commondomain.ext/
</VirtualHost>
But is it possible to match any (or at least wildcard) ServerName and redirect accordingly, i.e. with a backreference to a regex? Maybe with a DirectoryMatch or something instead of the vhost?
I have noticed this in the documentation (for directory and location matching), which is sadly not compatible with my version of Apache:
From 2.4.8 onwards, named groups and backreferences are captured and written to the environment with the corresponding name prefixed with "MATCH_" and in upper case. This allows elements of URLs to be referenced from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.
centos apache-2.4 redirect
centos apache-2.4 redirect
edited 5 hours ago
Leonard Challis
asked 6 hours ago
Leonard ChallisLeonard Challis
3031924
3031924
Possible duplicate of Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask
– Gerald Schneider
6 hours ago
I don't think it is.
– Leonard Challis
5 hours ago
I agree - this question is about how theServerNameandServerAliasdirective works in apache, rather than how mod_rewrite works.
– Jenny D
2 hours ago
add a comment |
Possible duplicate of Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask
– Gerald Schneider
6 hours ago
I don't think it is.
– Leonard Challis
5 hours ago
I agree - this question is about how theServerNameandServerAliasdirective works in apache, rather than how mod_rewrite works.
– Jenny D
2 hours ago
Possible duplicate of Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask
– Gerald Schneider
6 hours ago
Possible duplicate of Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask
– Gerald Schneider
6 hours ago
I don't think it is.
– Leonard Challis
5 hours ago
I don't think it is.
– Leonard Challis
5 hours ago
I agree - this question is about how the
ServerName and ServerAlias directive works in apache, rather than how mod_rewrite works.– Jenny D
2 hours ago
I agree - this question is about how the
ServerName and ServerAlias directive works in apache, rather than how mod_rewrite works.– Jenny D
2 hours ago
add a comment |
2 Answers
2
active
oldest
votes
With the backreferences only enabled in 2.4.8 (and me being on an earlier version) I figured an alternative solution which isn't pure apache config but works for me and may help others.
I added a new vhost config, like so:
<VirtualHost *:80>
ServerName 000_default_http.commondomain.ext
ServerAdmin technical@commondomain.ext
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/000_default_http/
<Directory /var/www/html/000_default_http/>
AllowOverride All
Require all granted
</Directory>
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_web.log 86400" combined env=!image
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_image.log 86400" combined env=image
ErrorLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_error.log 86400"
</VirtualHost>
Here, ServerName doesn't matter. Because we give it a filename of 000_default_http.conf it will be taken as the default vhost. What we do need to do is make sure all our vhost configs specify:
<VirtualHost *:443>
Then, whenever we visit any site at http:// it will use the above config. I then added the following to index.php in /var/www/html/000_default_http/:
<?php
if ($_SERVER['SERVER_PORT'] == '80') {
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit;
}
And made sure any directories were caught also, by adding a .htaccess file also:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
So now, any url, complete with path and query string, will be redirected from http to https.
Note that if you decided you did want an explicit HTTP site (or several) alongside the HTTPS ones, that's fine. Just make sure your 000_default_http.conf comes first alphabetically out of the configs with the *:80 virtual host. If Apache matches the ServerName on these configs on port 80, it will use them, otherwise it will continue using the above vhost and redirect to the HTTPS couterpart.
Obviously you can switch out the PHP for any language of your choice. But this method allows me to not bother with a seperate .htaccess directive on all sites and/or muddying up every vhost config file for the developer configs.
That said, if someone can come up with a nicer approach that can be done solely in apache config I'd be very interested in hearing it.
add a comment |
I'm using following vhost:
<VirtualHost *:80>
ServerName 'sub.domain.tld'
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
This redirects every HTTP request to HTTPS with the exact path
New contributor
r00tusr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f956634%2fis-it-possible-to-do-a-wildcard-http-https-redirect-for-all-vhosts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
With the backreferences only enabled in 2.4.8 (and me being on an earlier version) I figured an alternative solution which isn't pure apache config but works for me and may help others.
I added a new vhost config, like so:
<VirtualHost *:80>
ServerName 000_default_http.commondomain.ext
ServerAdmin technical@commondomain.ext
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/000_default_http/
<Directory /var/www/html/000_default_http/>
AllowOverride All
Require all granted
</Directory>
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_web.log 86400" combined env=!image
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_image.log 86400" combined env=image
ErrorLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_error.log 86400"
</VirtualHost>
Here, ServerName doesn't matter. Because we give it a filename of 000_default_http.conf it will be taken as the default vhost. What we do need to do is make sure all our vhost configs specify:
<VirtualHost *:443>
Then, whenever we visit any site at http:// it will use the above config. I then added the following to index.php in /var/www/html/000_default_http/:
<?php
if ($_SERVER['SERVER_PORT'] == '80') {
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit;
}
And made sure any directories were caught also, by adding a .htaccess file also:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
So now, any url, complete with path and query string, will be redirected from http to https.
Note that if you decided you did want an explicit HTTP site (or several) alongside the HTTPS ones, that's fine. Just make sure your 000_default_http.conf comes first alphabetically out of the configs with the *:80 virtual host. If Apache matches the ServerName on these configs on port 80, it will use them, otherwise it will continue using the above vhost and redirect to the HTTPS couterpart.
Obviously you can switch out the PHP for any language of your choice. But this method allows me to not bother with a seperate .htaccess directive on all sites and/or muddying up every vhost config file for the developer configs.
That said, if someone can come up with a nicer approach that can be done solely in apache config I'd be very interested in hearing it.
add a comment |
With the backreferences only enabled in 2.4.8 (and me being on an earlier version) I figured an alternative solution which isn't pure apache config but works for me and may help others.
I added a new vhost config, like so:
<VirtualHost *:80>
ServerName 000_default_http.commondomain.ext
ServerAdmin technical@commondomain.ext
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/000_default_http/
<Directory /var/www/html/000_default_http/>
AllowOverride All
Require all granted
</Directory>
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_web.log 86400" combined env=!image
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_image.log 86400" combined env=image
ErrorLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_error.log 86400"
</VirtualHost>
Here, ServerName doesn't matter. Because we give it a filename of 000_default_http.conf it will be taken as the default vhost. What we do need to do is make sure all our vhost configs specify:
<VirtualHost *:443>
Then, whenever we visit any site at http:// it will use the above config. I then added the following to index.php in /var/www/html/000_default_http/:
<?php
if ($_SERVER['SERVER_PORT'] == '80') {
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit;
}
And made sure any directories were caught also, by adding a .htaccess file also:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
So now, any url, complete with path and query string, will be redirected from http to https.
Note that if you decided you did want an explicit HTTP site (or several) alongside the HTTPS ones, that's fine. Just make sure your 000_default_http.conf comes first alphabetically out of the configs with the *:80 virtual host. If Apache matches the ServerName on these configs on port 80, it will use them, otherwise it will continue using the above vhost and redirect to the HTTPS couterpart.
Obviously you can switch out the PHP for any language of your choice. But this method allows me to not bother with a seperate .htaccess directive on all sites and/or muddying up every vhost config file for the developer configs.
That said, if someone can come up with a nicer approach that can be done solely in apache config I'd be very interested in hearing it.
add a comment |
With the backreferences only enabled in 2.4.8 (and me being on an earlier version) I figured an alternative solution which isn't pure apache config but works for me and may help others.
I added a new vhost config, like so:
<VirtualHost *:80>
ServerName 000_default_http.commondomain.ext
ServerAdmin technical@commondomain.ext
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/000_default_http/
<Directory /var/www/html/000_default_http/>
AllowOverride All
Require all granted
</Directory>
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_web.log 86400" combined env=!image
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_image.log 86400" combined env=image
ErrorLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_error.log 86400"
</VirtualHost>
Here, ServerName doesn't matter. Because we give it a filename of 000_default_http.conf it will be taken as the default vhost. What we do need to do is make sure all our vhost configs specify:
<VirtualHost *:443>
Then, whenever we visit any site at http:// it will use the above config. I then added the following to index.php in /var/www/html/000_default_http/:
<?php
if ($_SERVER['SERVER_PORT'] == '80') {
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit;
}
And made sure any directories were caught also, by adding a .htaccess file also:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
So now, any url, complete with path and query string, will be redirected from http to https.
Note that if you decided you did want an explicit HTTP site (or several) alongside the HTTPS ones, that's fine. Just make sure your 000_default_http.conf comes first alphabetically out of the configs with the *:80 virtual host. If Apache matches the ServerName on these configs on port 80, it will use them, otherwise it will continue using the above vhost and redirect to the HTTPS couterpart.
Obviously you can switch out the PHP for any language of your choice. But this method allows me to not bother with a seperate .htaccess directive on all sites and/or muddying up every vhost config file for the developer configs.
That said, if someone can come up with a nicer approach that can be done solely in apache config I'd be very interested in hearing it.
With the backreferences only enabled in 2.4.8 (and me being on an earlier version) I figured an alternative solution which isn't pure apache config but works for me and may help others.
I added a new vhost config, like so:
<VirtualHost *:80>
ServerName 000_default_http.commondomain.ext
ServerAdmin technical@commondomain.ext
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/000_default_http/
<Directory /var/www/html/000_default_http/>
AllowOverride All
Require all granted
</Directory>
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_web.log 86400" combined env=!image
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_image.log 86400" combined env=image
ErrorLog "|/usr/sbin/rotatelogs -l /var/log/httpd/000_default_http%Y%m%d_error.log 86400"
</VirtualHost>
Here, ServerName doesn't matter. Because we give it a filename of 000_default_http.conf it will be taken as the default vhost. What we do need to do is make sure all our vhost configs specify:
<VirtualHost *:443>
Then, whenever we visit any site at http:// it will use the above config. I then added the following to index.php in /var/www/html/000_default_http/:
<?php
if ($_SERVER['SERVER_PORT'] == '80') {
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit;
}
And made sure any directories were caught also, by adding a .htaccess file also:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
So now, any url, complete with path and query string, will be redirected from http to https.
Note that if you decided you did want an explicit HTTP site (or several) alongside the HTTPS ones, that's fine. Just make sure your 000_default_http.conf comes first alphabetically out of the configs with the *:80 virtual host. If Apache matches the ServerName on these configs on port 80, it will use them, otherwise it will continue using the above vhost and redirect to the HTTPS couterpart.
Obviously you can switch out the PHP for any language of your choice. But this method allows me to not bother with a seperate .htaccess directive on all sites and/or muddying up every vhost config file for the developer configs.
That said, if someone can come up with a nicer approach that can be done solely in apache config I'd be very interested in hearing it.
answered 4 hours ago
Leonard ChallisLeonard Challis
3031924
3031924
add a comment |
add a comment |
I'm using following vhost:
<VirtualHost *:80>
ServerName 'sub.domain.tld'
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
This redirects every HTTP request to HTTPS with the exact path
New contributor
r00tusr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I'm using following vhost:
<VirtualHost *:80>
ServerName 'sub.domain.tld'
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
This redirects every HTTP request to HTTPS with the exact path
New contributor
r00tusr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I'm using following vhost:
<VirtualHost *:80>
ServerName 'sub.domain.tld'
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
This redirects every HTTP request to HTTPS with the exact path
New contributor
r00tusr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm using following vhost:
<VirtualHost *:80>
ServerName 'sub.domain.tld'
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
This redirects every HTTP request to HTTPS with the exact path
New contributor
r00tusr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
r00tusr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 2 hours ago
r00tusrr00tusr
363
363
New contributor
r00tusr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
r00tusr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
r00tusr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f956634%2fis-it-possible-to-do-a-wildcard-http-https-redirect-for-all-vhosts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask
– Gerald Schneider
6 hours ago
I don't think it is.
– Leonard Challis
5 hours ago
I agree - this question is about how the
ServerNameandServerAliasdirective works in apache, rather than how mod_rewrite works.– Jenny D
2 hours ago