tags:

views:

562

answers:

4

Hello,

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.

A: 

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
A: 

Wow, that was quick. Thank you.

When I use

RewriteRule !^sub/ sub%{REQUEST_URI} [R]

in the .htaccess the physical path from the web server is added so it looks like: myhomepage.com/var/www/virtual/myhomepage.com/htdocs/sub.myhomepage.com

I thought I could get myhomepage.com/sub/ What do I miss?

When I try

RewriteRule !^/sub/ /sub/ [R]

I get the URL I want but the browser stops with "Redirect Loop". How can I prevent this?

A: 

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
A: 

Thanks, finally I got it to work with

RewriteRule ^$ /sub/ [R=301,L]

So far I didn't notice any draw backs. May be after some more tests I have to come back with additional questions. But so far thank you very much.