2 redirects

I’m trying to do 2 redirects in .htaccess:

  1. Redirect all traffic
    from http(s)://(www.)site.com/store.aspx and
    http(s)://(www.)site.com/store/*
    to https://store.site.com/store.aspx and https://store.site.com/store/*

  2. And on a different server…redirect all http://store.site.com to
    https://store.site.com

The following was used for www.site.com. I thought it would still work for
store.site.com but isn’t:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(store)(.*) https://%{HTTP_HOST}/$1$2 [R,L]

Any help would be greatly appreciated.

Thanks,
Mickey

Mickey,

You have me cconderned with your aspx file extensions as those imply an IIS server, not Apache. IIS has tried to imitate mod_rewrite but their directives are VERY different. That said, it looks like you’re merely exchanging the www subdomain for the store subdomain and ensuring that it’s using the https protocol. Rather than do LOTZA typing here, let me just refer you to the tutorial (WITH CODE EXAMPLES) linked in my signature and let you get the code there. It should be a simple matter to exchange the www for store while enforcing https.

As for the other code, what is in the world are you trying to do with (store)(.*)? Okay, assuming that the www => store is coded before this bit, you should not have a store directory as it’s likely the DocumentRoot for your subdomain (if not, please explain where the DocumentRoots are directed). I should think that all you need to do with this is force the https protocol (which the first RewriteRule will be doing) so this is superfluous. Nevertheless, if you’re intent on capturing and using the entire {REQUEST_URI}, I have to ask why! It’s already available as an Apache variable so merely use RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] (the 301 shows a permanent redirection whereas R defaults to 303 which is temporary).

Regards,

DK

Hi DK,

Thanks for responding. Let me explain this odd situation. Hopefully that will clear up what I’m trying to do and why.

The situation:
Site.com was a full custom built .net site with CMS and store with tons of bugs. I rebuilt the site in Drupal…except for the store. Still haven’t gotten to that piece yet. So the entire site (Drupal install and .net store) lived on a Windows 2003 VPS. We outgrew the server. So I moved most of the site to a Linux dedicated server…the Drupal part, that is. The .net store is still living on the old Windows VPS. The store is in the /store folder. But in order to have an SSL issued, I had to also make it a subdomain. So I set up store.site.com where the store is still living in /store. Moving it to the root would be a ton of heading with hard-coded URLs! Hence store.site.com/store. So no Apache for the .net portion. (Not to worry!!!)

So for the store on the Windows server, I just need to make sure everything can only be accessed through SSL.

For the Drupal install for the rest of the site on the Linux server, I need to make sure that any calls to the old URLs for the store (site.com/store.aspx and site.com/store/*) are redirected to the subdomain on the Windows server.

Hope this makes sense. I’ll check out the link in your sig for #2. Hoping for help with #1.

Thanks!
Mickey

Woops. Should have also mentioned I’m using isapi_rewrite on the Windows server. I’m sure there are limitations with it but for the simple stuff I’ve done, I haven’t encountered any problems.

Ok, got part 2 going on the Windows server. Just need to figure out part 1.

Thanks,
Mickey

Ok, got the first part working with the following:

RewriteRule ^/?(store)(.*) https://store.site.com/$1$2 [R,L]

Not sure if it’s correct but it works. Feedback still appreciated.

Thanks!
Mickey

Mickey,

This situation probably isn’t so odd. Just think of the subdomain as another domain and you’ll be off to the races!

Part 1: So for the store on the Windows server, I just need to make sure everything can only be accessed through SSL.

That’s something that will have to be done on the Windows server. It shouldn’t be difficult to set it up to operate ONLY via https protocol - and you’re quite correct about the cert for the subdomain.

For the Drupal install for the rest of the site on the Linux server, I need to make sure that any calls to the old URLs for the store (site.com/store.aspx and site.com/store/*) are redirected to the subdomain on the Windows server.

I see that you got that code from the tutorial - just be sure that it redirects everything sent to the store subdirectory.

RewriteRule ^/?(store)(.*) https://store.site.com/$1$2 [R,L]

R defaults to a 303 (temporary) redirection. Assuming that you’re doing to keep store as a subdomain, I’d change R to R=301 so SE’s (and everyone else) knows that’s a permanent change.

Regards,

DK

Hi David,

Thanks again for your reply. Regarding the temporary or permanent redirect…

This change is just temporary…they’re going to be rebuilding the cart inside Drupal. When this happens, the subdomain will be gone again and the store will once again list at /store. But that’s several months down the line at a minimum. So, is a 303 or 301 better? How permanent is permanent?

Thanks,
Mickey

Permanent here means the the browser is allowed to cache the redirect. In other words, when you remove the redirect, browsers that already followed the continue to follow it, even though it doesn’t exist anymore.

If it’s really temporary than status 302 will be your better choice.
Actually it should be 303, but older browsers don’t understand 303 and most browsers handle 302 as if it’s a 303 anyway.

@David, the R flag defaults to 302, not 303

Rémon,

:tup:

Regards,

DK