Home How do I force https and then match a RewriteRule that redirects from an old sub-directory to a new sub-directory?
Reply: 0

How do I force https and then match a RewriteRule that redirects from an old sub-directory to a new sub-directory?

user47659
1#
user47659 Published in September 20, 2018, 9:14 pm

Here is the code that I've written and an explanation below:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.webringtheparty.com/$1 [R=301, NC]

RewriteBase /category/
RewriteRule ^our-rentals/concessions-tents-tables-chairs/generator-rental generators [R=301,L]
RewriteRule ^our-rentals/bounce-slide-combos-rentals/(.*) combo_bounce_house_rentals [R=301,L]
RewriteRule ^product-tag/moonwalk-combo combo_bounce_house_rentals [R=301,L]

RewriteBase /
RewriteRule ^policies faq [R=301,L]
RewriteRule ^about-us-moonwalk-rentals /  [R=301,L]
RewriteRule ^contact-us contact  [R=301,L]

I have an old domain name that I would like to redirect to my new domain and force https://www. The old domain name is

http(s)://webringtheparty.ourers.com/ 

and the new domain is

http(s)://(www.)webringtheparty.com/

I have setup

https://www.webringtheparty.com 

as the main entry in my search console so I would like to force this format on all requests.

The problem with my code is that if I have written the URL as

http://webringtheparty.ourers.com 

or

http://webringtheparty.com

and it redirects to the format that I want to force then no other RewriteRules are getting matched.


Here is the website I'm using to test the .htaccess rules:

https://htaccess.mwl.be/

Using the "Request URL" below and the .htaccess rules above I am expecting the "Expected Output URL" below, but it ends up as the "Actual Output URL" below:

Request Url: http://webringtheparty.ourers.com/about-us-moonwalk-rentals

Expected Output Url: https://www.webringtheparty.com/

Actual Output Url: https://www.webringtheparty.com/about-us-moonwalk-rentals

share|improve this question
  • Is it the entire content of your .htaccess file? Is the document root the same for both domains? If not - are you 100% sure that this .htaccess file is placed in both the directories? – Jakub Krawczyk Feb 13 at 19:03
  • The document root is the same and I've only removed additional RewriteRules for redirecting similar directories. I've only tested it on the linked website though and haven't had a chance to try it on my live server. – Bradley Feb 13 at 20:16
  • You should definitely check it on your server (maybe on some development subdomain if you don't want to break anything on live environment) - these rules seem ok. This tool does not perform the redirect, so it shows you the output after the first iteration. If you then use: webringtheparty.com/about-us-moonwalk-rentals as the input, the output would be your expected URL. – Jakub Krawczyk Feb 13 at 20:41
  • @Jakub Krawczyk Thanks and the line after the RewriteCond has the flags NC, is that correct or should it be just N? – Bradley Feb 13 at 20:58
  • Try to look into the documentation first as it can usually provide answers to the most common questions. Then try to play with the htaccess rules yourself and then if you are stuck, ask the question here. I am sure that the SO community would like to help, but own experience is priceless and there is a chance of learning something new while exploring options. NC and N flags are two different things so it depends on what you are trying to achieve. – Jakub Krawczyk Feb 14 at 9:44

active oldest votes

Your Answer

StackExchange.ifUsing("editor", function () { StackExchange.using("externalEditor", function () { StackExchange.using("snippets", function () { StackExchange.snippets.init(); }); }); }, "code-snippets"); StackExchange.ready(function() { var channelOptions = { tags: "".split(" "), id: "1" }; 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', convertImagesToLinks: true, noModals: false, showLowRepImageUploadWarning: true, reputationToPostImages: 10, bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".discard-answer" ,immediatelyShowMarkdownHelp:true }); } });
 
StackExchange.ready( function () { StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48773227%2fhow-do-i-force-https-and-then-match-a-rewriterule-that-redirects-from-an-old-sub%23new-answer', 'question_page'); } );

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged php apache .htaccess redirect mod-rewrite or ask your own question.

StackExchange.ready(function(){$.get('/posts/48773227/ivc/ca21');});
StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); }) (function(i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); StackExchange.ready(function () { StackExchange.ga.init({ sendTitles: true, tracker: window.ga, trackingCodes: [ 'UA-108242619-1' ] }); StackExchange.ga.setDimension('dimension2', '|php|apache|.htaccess|redirect|mod-rewrite|'); StackExchange.ga.setDimension('dimension3', 'Questions/Show'); StackExchange.ga.trackPageView(); }); /**/ var _qevents = _qevents || [], _comscore = _comscore || []; (function() { var ssl = 'https:' == document.location.protocol, s = document.getElementsByTagName('script')[0], qc = document.createElement('script'); qc.async = true; qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve.com/quant.js'; s.parentNode.insertBefore(qc, s); _qevents.push({ qacct: "p-c1rF4kxgLUzNc" }); /**/ var sc = document.createElement('script'); sc.async = true; sc.src = (ssl ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js'; s.parentNode.insertBefore(sc, s); _comscore.push({ c1: "2", c2: "17440561" }); })();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33704 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO