2

I need to redirect myhomepage.com/ to myhomepage.com/sub/

When I read the guide at apache.org/docs/1.3/misc/rewriteguide.html I have no clue what they are talking about. Hence I decided to friendly ask one of the experts here. I guess it takes just some seconds to figure that rule out.

Thanks, Carin.

2 Answers2

5

Try this rule:

RewriteRule !^sub/ sub%{REQUEST_URI}

It will redirect any requested URL path that does not start with /sub/ (!^sub/) internally to /sub/ (sub%{REQUEST_URI}).

This rule is for the .htaccess configuration file in your document root. If you want to use it in your httpd.conf, prepend the pattern with a /.

And if you want an external redirect, prepend the substition with a / too and add the [R] flag:

RewriteRule !^sub/ sub%{REQUEST_URI} [R]
Gumbo
  • 643,351
  • 109
  • 780
  • 844
0

If you only want to redirect http://myhomepage.com/ (i.e. you don't need to redirect http://myhomepage.com/example.html to http://myhomepage.com/sub/example.html), the rule is as simple as:

RewriteRule ^$ http://myhomepage.com/sub/ [R=301,L]
ceejayoz
  • 176,543
  • 40
  • 303
  • 368