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

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

Apache Web Server Forum

redirect home page to /home

 2:36 pm on Jul 14, 2010 (gmt 0)

Hello again,
I was trying to find on this forum a way how to redirect the main page to /home, but didn't succeed. Please write me the rule or direct me into to correct thread.
(i want to come from www.example.com to www.example.com/home/en)
this code doesn't do it, maybe you can also show me what is wrong here:
RewriteCond %{THE_REQUEST} ^([A-Z]{3,9}\ /) [NC]
RewriteRule ^(.*)$ http://www.example.com/home/en[R=301,NC]

thanks in advance




 3:30 pm on Jul 14, 2010 (gmt 0)

If your "main page" is "www.example.com/" then the rule would be:

RewriteRule ^$ http://www.example.com/home/en [R=301,L]

The original RewriteCond does nothing, and is therefore not needed.



 8:36 am on Jul 15, 2010 (gmt 0)

together with another rules it creates loop I can't see. There is only one related to /home, but i still can't see it:

RewriteRule ^$ http://www.example.com/home/en? [R=301,L]

RewriteRule ^(home)\/(en|sk|cz|pl|hu)$ ?lang=$2 [NC,L]

without the question mark, it adds the "?lang=en" at the end when accessing the homepage. that's why i was trying to use the THE_REQUEST before, but without success.


 8:46 am on Jul 16, 2010 (gmt 0)

since the rule you have send me wouldn't work in combination with my other rules, I have added one condition, which works, but do you see any potentional problems here?

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$ http://www.example.com/home/en [R=301,L]


 1:54 am on Jul 17, 2010 (gmt 0)

mod_rewrite in .htaccess is recursive. That is, after any rule has been invoked, mod_rewrite begins processing all rules again. This is the cause of your loop.

The usual solution is to use THE_REQUEST, so that only direct client requests for the query-string URL are redirected:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /\?lang=(en|sk|cz|pl|hu)\ HTTP/
RewriteRule ^$ http://www.example.com/home/%1? [R=301,L]
RewriteRule ^home/(en|sk|cz|pl|hu)$ /?lang=$1 [NC,L]


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