Welcome to WebmasterWorld Guest from 54.227.83.19

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

This page is not redirecting properly (htaccess)

Yep, another htaccess question

     

rubenski

4:14 pm on Oct 26, 2011 (gmt 0)

10+ Year Member



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

8:50 pm on Oct 26, 2011 (gmt 0)

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



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

10:11 pm on Oct 26, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



!^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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month