views:

300

answers:

1

Hi,

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! :))

+3  A: 

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
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
Whoops - minor typo: I meant to say "anyone accessing example.com/abcde/ to be redirected to example.com/other.php?subfolder=abcde"
Steve