1

I have a domain example.com. I want users to be redirected to https://www.example.com whenever one of the following is typed:

  • http://example.com
  • http://www.example.com
  • https://example.com

I also need to redirect people accessing /asdf (or /asdf/) to /index.php?folder=asdf.

I found some examples of code doing the first part, but there was always a debate about their effectiveness.


Edit: (need some more help! :))

Steve
  • 1,857
  • 5
  • 32
  • 45
  • Hmm - I think I should have posted my addon query here... :) [its below in response to Gumbo] – Steve Oct 29 '09 at 15:59

1 Answers1

3

Try these mod_rewrite rules:

RewriteEngine on

RewriteCond %{HTTP_HOST} !=www.example.com [OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]

RewriteCond $1 !=index.php
RewriteRule ^([^/]+)/?$ index.php?folder=$1 [L]

But I recommend you to just allow one URL notation, the one with or without the trailing slash.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • Hi there Gumbo - The first part of it works quite well, but for the second part, I need some more help. I want all users accessing "www.example.com" to access a "index.html" file, but anyone accessing example.com/abcde/ to be redirected to example.com/subfolder=abcde . One more complication is that I have a special (but "real") folder at: www.example.com/qwerty/ . Any links within those should not be altered. Thanks! Your earlier example was very helpful! – Steve Oct 29 '09 at 02:47
  • Whoops - minor typo: I meant to say "anyone accessing example.com/abcde/ to be redirected to example.com/other.php?subfolder=abcde" – Steve Oct 29 '09 at 09:23