www being stripped from url

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
curlypinky
Forum Members
Forum Members
Posts: 109
Joined: Thu Sep 04, 2008 3:49 am
Location: Hawaii

www being stripped from url

Post by curlypinky »

I've got an unusual problem that I am unsure where it stems. "www" is stripped from the url when you go to it by the internal links.

I am using the htaccess mod rewrite engine for pretty urls and when you view the link destination it shows as http://www.site but when you click on the link it takes you to the page but the url is http://site .I am not sure where the root of the problem lies and I need it to obey the www to make use of pngfix.

The site is http://www.konatraveler.com

Please excuse, it is unfinished and I'm still working out the layout kinks.

Config is set to $config['root_url'] = 'http://www.konatraveler.com';

htaccess:

Code: Select all

Options +FollowSymLinks
#
<IfModule mod_rewrite.c>
RewriteEngine on
#
#Sub-dir e.g: /cmsms
RewriteBase /
#
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
Thank you!
Alane
curlypinky
Forum Members
Forum Members
Posts: 109
Joined: Thu Sep 04, 2008 3:49 am
Location: Hawaii

Re: www being stripped from url

Post by curlypinky »

So it seems related to my mod-rewrite, I disabled it and the pages are keeping their www. prefix when you reach them. I am not very experienced with rewrite so I will experiment
curlypinky
Forum Members
Forum Members
Posts: 109
Joined: Thu Sep 04, 2008 3:49 am
Location: Hawaii

Re: www being stripped from url

Post by curlypinky »

I've resorted to an extra rewrite rule to force the www:

Code: Select all

RewriteCond %{HTTP_HOST} !^www\.konatraveler\.com [NC]
RewriteRule ^(.*)$ http://www.konatraveler.com/$1 [L,R=301]
But, does this seem normal that the default mod rewrite rules are stripping the www? I don't have another site I can test out to see if the prefix being removed is isolated to just this site or if it affects all sites. I do have a new project coming up which I will test it on. 

This is the full htaccess file:

Code: Select all

# Attempt to override some php settings, these settings may be helpful on some hosts if your
# default configuration does not meet CMS's minimum requirements, and your host
# has given your account appropriate permissions
#php_value upload_max_filesize "10M"
#php_value session_save_path "tmp/cache"
#php_value memory_limit "64M"

#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off

# (this is important, so uncomment if your host permit)
#Options -Indexes
#ServerSignature Off
#
Options +FollowSymLinks
#
<IfModule mod_rewrite.c>
RewriteEngine on
#
#Sub-dir e.g: /cmsms
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.konatraveler\.com [NC]
RewriteRule ^(.*)$ http://www.konatraveler.com/$1 [L,R=301]
#
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
Jean le Chauve

Re: www being stripped from url

Post by Jean le Chauve »

I had a problem too with the ajax requests
I made this extra into the .htaccess

Code: Select all

RewriteCond %{HTTP_HOST} ^domaine.com$ [NC]
RewriteRule ^(.*)$ http://www.domaine.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^.*domaine.com [NC]
RewriteRule (.*) http://www.domaine.com/$1 [R=301,L]
Edit : the two last lines made a second redirection => forget me ;)
Last edited by Jean le Chauve on Sun May 17, 2009 10:03 am, edited 1 time in total.
User avatar
CMSMS-Fan
Forum Members
Forum Members
Posts: 76
Joined: Tue Feb 28, 2006 5:35 pm

Re: www being stripped from url

Post by CMSMS-Fan »

I may have the wrong end of the stick but if you install a website using CMSMS installer it writes the config.php without the www. If you open the config.php and search for the domain name you will see it is written in line 77 as

Code: Select all

$config['root_url'] = 'http://yourdomain.com';
  Simply add the www. and then the urls will be correct.

Code: Select all

$config['root_url'] = 'http://www.yourdomain.com';
Often Ignored but never forgotten
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: www being stripped from url

Post by Jeff »

HuttonIT,

curlypinky said in the op that:
Config is set to $config['root_url'] = 'http://www.konatraveler.com';
User avatar
CMSMS-Fan
Forum Members
Forum Members
Posts: 76
Joined: Tue Feb 28, 2006 5:35 pm

Re: www being stripped from url

Post by CMSMS-Fan »

It is just that I find that when I install CMSMS I have to change it to add the www. or you get an error when someone arrives at your site.  It never used to do that but since about 3 or 4 updates ago it started so I had to go into all my sites and change them all.
Often Ignored but never forgotten
User avatar
LeslieB22
New Member
New Member
Posts: 5
Joined: Thu Jul 03, 2008 11:33 am
Location: Berlin, Germany

Re: www being stripped from url

Post by LeslieB22 »

Hi, I'm having pretty much the same problem. I would like to force www to be used, as well as the trailing slash. I'm also not very well versed in mod_rewrite, but did piece together code that manages to get both www and the trailing slash on in the end. However, it seems to result in more redirects than should be necessary.

For example, a URL that already has www but not the trailing slash is first redirected to a URL with the slash but WITHOUT the www, then to a URL with both www and slash.

Here's the server headers:
#1 Server Response: http://www.yoga-lotos.de/wellness
HTTP Status Code: HTTP/1.1 301 Moved Permanently
Redirect Target: http://yoga-lotos.de/wellness/

#2 Server Response: http://yoga-lotos.de/wellness/
HTTP Status Code: HTTP/1.1 301 Moved Permanently
Redirect Target: http://www.yoga-lotos.de/wellness/

#3 Server Response: http://www.yoga-lotos.de/wellness/
HTTP Status Code: HTTP/1.1 200 OK
Here's my mod_rewrite code:

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(robots\.txt|favicon\.ico|sitemap\.xml)$
RewriteCond %{HTTP_HOST} !^www\.yoga-lotos\.de$ [NC]
RewriteRule ^(.*)$ http://www.yoga-lotos.de/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
I'm guessing if I really study this documentation on the Apache site -http://httpd.apache.org/docs/2.2/rewrite/rewrite_intro.html, I will eventually be able to solve this myself. But if someone has already found a good solution, I'd be grateful to hear it!
Post Reply

Return to “The Lounge”