homepage Welcome to WebmasterWorld Guest from 54.226.213.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Temporary redirect of homepage to directory
Need mod_rewrite rule to redirect visitors who come to homepage
OrganicPop




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

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




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

> 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




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

Hi Jim, the following extensions are accesible

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

Thanks for your help

jdMorgan




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved