Forum Moderators: phranque

Message Too Old, No Replies

Redirect URL

redirecting to a specific directory

         

tristate

4:10 pm on Mar 3, 2005 (gmt 0)



I would like to redirect my url as follows

www.domain.com to www.domain.com/mydir/

I have the following in my custom settings

RewriteEngine On

RewriteCond %{HTTP_HOST}!^www\.domain\.com [NC]

RewriteRule ^/$ /mydir/ [R]

But the problem is only if someone types

domain.com it goes to that mydir other wise not.

Please help me in this regard

Again My requirement is

[domain.com...] -> [comain.com...]
domain.com -> [comain.com...]
www.domain.com -> [comain.com...]
[domain.com...] [comain.com...]

jdMorgan

4:30 am on Mar 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



tristate,

Welcome to WebmasterWorld!

The "http://" part is required to specify the protocol used to connect to your server; It is not formally part of the URL visible to RewriteRule. So, your problem reduces to:

domain.com -> http://www.domain.com/mydir/
www.domain.com -> http://www.domain.com/mydir/

The only added complication is that steps must be taken to prevent an infinite redirection loop.


RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^/(.*) http://www.domain.com/$1 [R=301,L]
#
RewriteCond %{REQUEST_URI} !^/mydir/
RewriteRule ^/(.*) /mydir/$1 [L]

I have assumed that you *do not* want the /mydir/ subdirectory to be visible to the user, but that you *do* want the domain.com-to-www.domain.com redriection to be visible.

I have further assumed that this code goes into httpd.conf, rather than .htaccess.

For more information, see the references cited in our forum charter [webmasterworld.com].

Jim