Forum Moderators: phranque

Message Too Old, No Replies

removing www. from url in a sub folder

         

seancon1

5:06 pm on Jan 27, 2011 (gmt 0)

10+ Year Member



i have a situation where i have a billing software package in a sub folder of a wordpress site domain.com/billing and the cookies are conflicting when you login to the billing software. the billing software uses domain.com for its cookies and according to the developer cant be changed easily.
wordpress also used domain.com but i can change it to use www.domain.com
and for the most part this solved the cookie login issue. unless someone types in www.domain.com/billing

my wordpress is configured to use www.domain.com and i have this rewrite in the root folder .htaccess.

<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>


this works fine.

in the domain.com/billing folder i would like to do the opposite and remove the www. to make sure the url is correct.

i have tried different variations of the above with out success. i understand the .htaccess is recursive so i am not sure if this should be in the root htaccess file or in an additional .htaccess file in domain.com/billing

thank you in advance for any suggestions on how to get this working.

Sean

g1smd

8:44 pm on Jan 27, 2011 (gmt 0)

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



Because the rule in the root redirects "all" requests to www, adding a rule in the folder redirecting to non-www will result in an infinite loop.

Put all the rules in the root.

In one rule, test for:
REQUEST_URI ^/folder
and
HTTP_HOST ^www
.
Redirect to non-www.

In the other rule, test for:
REQUEST_URI !^/folder
and
HTTP_HOST !^www
.
Redirect to www.

seancon1

7:44 pm on Jan 28, 2011 (gmt 0)

10+ Year Member



thank you, that put me back on the right track... the "AND" threw me off a bit as it seems those need to be in separate lines. but i have it working as long as i dont use the folder name as part of the Wordpress permalink.

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
RewriteCond %{REQUEST_URI} ^/folder
RewriteCond %{HTTP_HOST} ^www.
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
</IfModule>

thanks for the pointer!

Sean