Welcome to WebmasterWorld Guest from 54.146.239.96

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Temporary redirect of homepage to directory

Need mod_rewrite rule to redirect visitors who come to homepage

     

OrganicPop

2:47 pm on Aug 4, 2006 (gmt 0)

5+ Year Member



Simple question that I can't seem to nail down. Can anyone help redirect my homepage using mod_rewrite, from [domain.com,...] to my blog [domain.com...]

This is a temporary move just so i can post on my weblog about the design of the site and such. When I’m done designing I would switch back to the top level.

Any help would greatly be appreciated.

Oh and I’ve tried numerous combinations to no avail. Here is my current .htaccess

#temporary redirect homepage to weblog
RewriteCond %{REQUEST_URI}!^/weblog/
RewriteCond %{HTTP_HOST} domain.com$
RewriteRule ^(.*)$ weblog/$1 [L]

Thanks!

jdMorgan

5:22 pm on Aug 4, 2006 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



> redirect my homepage

I assume your home page is available at "example.com/". Is it also accessible using another URL, such as "example.com/index.html"? Unless you want to take the risk of weird search indexing problems, we need to know any and all URLs that can be used to reach your homepage.

Jim

OrganicPop

6:47 pm on Aug 4, 2006 (gmt 0)

5+ Year Member



Hi Jim, the following extensions are accesible

[domain.com...]
[domain.com...]
[domain.com...]
[domain.com...]

Thanks for your help

jdMorgan

2:20 pm on Aug 5, 2006 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Here's the recommended method:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.(php¦html?))?\ HTTP/
RewriteCond ^(index\.(php¦html?))? http://www.example.com/ [R=301,L]

You could simplify the code by picking the one 'real' URL for the actual file, for example, "index.html," and doing this:

DirectoryIndex index.html
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.html)?\ HTTP/
RewriteCond ^(index\.html)?$ http://www.example.com/ [R=301,L]

This overrides the 'catch-all' DirectoryIndex --which was probably defined by your host-- that includes all those other variations, and defines only "index.html" as the 'real' path to the index file to be used when "/" is requested.

The construct shown above, testing THE_REQUEST, is necessary to prevent an 'infinite loop' when redirecting "index.html" to "/". This loop would normally occur because, in effect, DirectoryIndex rewrites "/" to "index.html". If the THE_REQUEST RewriteCond wasn't used, then the rule would redirect "index.html" to "/" and DirectoryIndex would immediately rewrite it back. If the rule wasn't qualified to look at only the original client request, then this would lead to a loop which would end only when the client (e.g. browser) or server reached its maximum redirection limit.

Note that THE_REQUEST contains the entire client request header, as seen in your raw server logs. For example, it might contain

GET /index.html HTTP/1.1
or
PROPFIND /index.html HTTP/1.1

including the HTTP_method, the local URL-path, and the protocol. So that's what all the additional regular-expressions pattern stuff in the RewriteCond is intended to match.

Change all broken pipe "¦" characters above to solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

 

Featured Threads

Hot Threads This Week

Hot Threads This Month