Welcome Guest, Not a member yet? Register   Sign In
I want both www and non-www to work !
#1

(This post was last modified: 03-21-2015, 07:46 AM by invader7.)

Hello forum , i need your help about my codeigniter site.

I have an iOS application which makes a POST request to my site with www

example : http://www.mysite....

The response is 301 moved permanently and i can never get the POST data.

If i make the POST request to non-www

example : http://mysite...

Everything works fine !


So here is my current configuration

system/application/config/config.php

Code:
$config['base_url'] = 'http://mysite.....';
$config['base_url_static'] = 'http://mysite.....';
$config['base_url_videos'] = 'http://mysite.....';

.htaccess

Code:
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1


and my apache virtualhost configuration file

sites-available/mysite.com


Code:
<VirtualHost *:80 >
       ServerName www.mysite.com
       ServerAlias www.mysite.com
</VirtualHost>

any ideas ??

Thanks !!
Reply
#2

Just removed these 2 lines from you htaccess. That part removes "www" from any request.

Code:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1

Also, I would recommend you update your mysite.conf to

Code:
<VirtualHost *:80 >
      ServerName www.mysite.com
      ServerAlias mysite.com
</VirtualHost>

So it can detect both www and none www without issues.
Reply
#3

Note that this can potentially cause duplicate content issues with search engines if you allow both www and non-www. You really should use one or the other, but not both, especially in links or you can have a fall in your search engine rankings.
Reply
#4

http://moz.com/learn/seo/canonicalization

Just put a link tag (with rel="canonical") in your document's head to point to the canonical version (with or without the www, whichever you prefer, just be consistent). Then the search engines won't hurt your rankings for letting your users browse from either URL.

The same can be done for many other situations in which you may end up with "duplicate content": http://moz.com/blog/canonical-url-tag-th...e-sitemaps
Reply
#5

Thanks a lot, for your advices , my mysite.conf was as silentium's but i wrote it wrong without realizing it. I had this part right.

The problem was with the htaccess, i removed the 2 lines you mentioned and it solved the problem.
Reply
#6

(03-23-2015, 12:39 PM)invader7 Wrote: Thanks a lot, for your advices , my mysite.conf  was as silentium's but i wrote it wrong without realizing it. I had this part right.

The problem was with the htaccess, i removed the 2 lines you mentioned and it solved the problem.

Glad I could help.

I would recommend you, as mentioned in above replies, only use either www or none www urls.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB