Forum Moderators: phranque

Message Too Old, No Replies

Non-WWW to WWW with Sub-directories ?

Request a Rewrite Rule modification to include subdirectories

         

brite

12:19 pm on May 21, 2009 (gmt 0)

10+ Year Member



Hey Folks,

I've been searching for a non-www to www set of rewrite rules, and found this fine post by jdMorgan:


Link: Non-WW to WWW [webmasterworld.com]

# Externally redirect from non-www, non-canonical hostname to the
# canonical www hostname, preserving current HTTP/HTTPS protocol
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{SERVER_PORT}s ^(443(s)¦[0-9]+s)$
RewriteRule (.*) http%2://www.example.com/$1 [R=301,L]

Replace the broken pipe "¦" character in the second RewriteCond pattern with a solid pipe before use; Posting on this forum modifies the pipe characters.

However, I was trying to adjust this (unsuccessfully) to also include any requests with subdirectories, such as:

http://example.com/clients REWRITE_TO-> http://www.example.com/clients

Can someone lend a hand on adding this modification? Thanks much

~Brite

jdMorgan

12:45 pm on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you test the original code before posting?

No modification is required, as the requested URL-path (i.e. the "directory" and "file name" part) is captured by the RewriteRule pattern as "$1", and re-injected into the redirect target URL.

See the resources cited in our Forum Charter for more information.

Jim

brite

1:10 pm on May 21, 2009 (gmt 0)

10+ Year Member



Yes, i tested prior to posting and it didn't work. Guess there is an issue on my end. Thanks for the response

jdMorgan

1:30 pm on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be sure that you've changed the broken pipe "¦" character to a solid pipe character before trying to use any code you find posted here (and on several other forum sites). Posting on this forum modifies the pipe character, and the code won't work unless you replace it. This warning is almost always included with code posted here.

Jim

brite

2:05 am on May 22, 2009 (gmt 0)

10+ Year Member



Hi Jim,

Thanks again. Issue was on my end with another re-write rule within a sub-directory causing this one to not function properly.

Curious if this Rewrite rule can be modified to force HTTPS?

g1smd

2:09 am on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes. If the target URL says
https://
instead of
http$2://
and some other simplifications are made.