homepage Welcome to WebmasterWorld Guest from 54.237.213.31
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
This page is not redirecting properly (htaccess)
Yep, another htaccess question
rubenski

10+ Year Member



 
Msg#: 4379613 posted 4:14 pm on Oct 26, 2011 (gmt 0)

Hi,

My site uses htaccess to rewrite all incoming requests to /index.php. I am now trying to add new lines to rewrite all example.com/... URLs to www.example.com/... The solution below isn't working, because it causes the site to "not redirect properly". I think it ends in a redirection loop. Could you help out?

#this is new and should rewrite example.com to www.example.com
RewriteCond %{HTTP_HOST} !^www..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*).(net|net/)
RewriteRule ^.*$ www.%1.%2%{REQUEST_URI} [R=301,L]

#this is what I already had and works.
RewriteRule ^(.*)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/static/
RewriteRule ^(.*)$ index.php

 

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4379613 posted 8:50 pm on Oct 26, 2011 (gmt 0)

RewriteCond %{HTTP_HOST} ^([^.]*).(net|net/)
RewriteRule ^.*$ www.%1.%2%{REQUEST_URI} [R=301,L]


What is this pair of lines intended to do? Trying to sort it out has given me a headache so let's just stipulate that, whatever it is, it isn't doing it.

Or you can search for "www redirect" in this Forum. There should be several hundred threads within the past year.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4379613 posted 10:11 pm on Oct 26, 2011 (gmt 0)

!^www..* -- the trailing unactioned .* just wastes processor cycles, literal periods should be escaped, use !^www\. only.

^([^.]*).(net|net/) -- code has multiple issues: escape the literal period, hostname never ends in / here, you need $ end anchor, and [^.]* matches a blank, as in http: // .net -- use ^([^.]+)\.net(:[0-9]+)?$ to also ensure you redirect requests with an appended port number.


#this is new and should rewrite example.com to www.example.com

-- no it does not. It is a redirect not a rewrite.


#this is what I already had and works.

-- the first rule should include the protocol and domain name in the rule target,
-- the second rule needs the [L] flag.

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