CodeIgniter Forums
[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh (/showthread.php?tid=3406)



[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-28-2007

[eluser]Sarfaraz Momin[/eluser]
Hi,
I have deployed the new CI site yesterday and have missed a very small but important aspect of the site which is everytime a user uses a url http://domain.com it redirects to http://www.domain.com which is bad because there are thousands of pages linking to my site using http://domain.com and the pagerank too is very high which i doubt would be lost. In short my boss wants the site to work as it use to work previously i.e. it should work with http://domain.com without redirecting and http://www.domain.com is always working. Also to mention if I call a controller directly using http://domain.com/controller it works fine without redirecting. I have been checking the router and URI library for any traces but could not find any. I think this is something which I overlooked and now i think i might pay a very heavy price for it. Please all of you CI gurus help me with this.


[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-28-2007

[eluser]Derek Allard[/eluser]
If its redirecting without the user even clicking on anything, then its either an htaccess file, or your host has some funky redirect going on. Want to post your htaccess so we can take a look?


[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-29-2007

[eluser]Sarfaraz Momin[/eluser]
Thanks for a prompt reply david. I do not think the issue is with htaccess since there is no rule for such redirection. Well as I defined earlier the internal pages are working with http://domain.com/category/ without rewriting the URL in the address bar to http://www.domain.com the problem stays only with the homepage. The homepage for some reason does not want to work the way I want. Even if i put http://www.domain.com/index.php it redirects to http://www.domain.com. Please help as this is getting a little more critical than I expected. The following are the contents of my htaccess file.



Code:
Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|css|stylesheets|image|img|js|adminimg)
RewriteRule ^(.*)$ /index.php?$1 [L]



[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-29-2007

[eluser]John_Betong[/eluser]
Hi Sarfaraz Momin,

Take a look at this site, it has quite a few good examples which I believe will solve your problem:

http://www.sitepoint.com/article/apache-mod_rewrite-examples/2
Quote:1. Forcing www for a domain while preserving subdomains

RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.xample.com%{REQUEST_URI} [R=301,L]

This rule captures the optional subdomain using the %1 variable, and, if it doesn't start with www., redirects with www. prepended to the subdomain. The domain and the original {REQUEST_URI} are appended to the result.

2. Eliminating www from a domain

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L]

Don't forget to let us know if you find a solution.

Cheers,

John_Betong
 


[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-29-2007

[eluser]Sarfaraz Momin[/eluser]
Hi,
Thanks guys for your replies but I think I am not able to explain the issue properly. Let me try it again. I am little comfortable with htaccess and can understand the rewrite rules. I am sure the problem is not with htaccess. The issue seems to be somewhere when the index.php of CI is called. I say so because if I use url like http://domain.com/test.php in my browser it works fine and does not redirect me http://www.domain.com/test.php. I am sure there is something in router.php which is doing this but i am unaware for what it is.


[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-29-2007

[eluser]Derek Allard[/eluser]
Hey, who's David? Wink

What does your config/config.php say under $config['base_url']?


[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-29-2007

[eluser]Sarfaraz Momin[/eluser]
Sorry Derek,
With this you can imagine the amount of frustration I am going through. This are some settings in my config.php

Code:
$config['base_url']    = "http://www.domain.com/";

$config['index_page'] = "index.php";

$config['uri_protocol']    = "REQUEST_URI";

I have already tried changing the base url to http://domain.com but it does not help. I have also tried "http://".$_SERVER["HTTP_HOST"] but even that did not help.


[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-29-2007

[eluser]Derek Allard[/eluser]
Honestly, this sounds like your host is doing a redirection. Do you have a local test system you could put your code on? I be it works perfectly. If it does, then I'd contact your host and ask them if they have anything funky going on. I know some hosts have options to automatically move you when you set up a domain. Ask them if they've done that.


[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-29-2007

[eluser]Sarfaraz Momin[/eluser]
Well its a dedicated server and I manage it myself through plesk control panel. Is there anything specific you want me to check but i can still assure you that there is nothing on the server. In the mean time I did another test. I renamed the index.php provided by CI and made a new index.php with the following contents.
Code:
<?php
phpinfo();
?>

VOILA !!! it did not redirected me when I put http://domain.com in the browser it stayed there and showed me the php settings. Isn't this getting irritating now. Do you want me to check anything else apart from this. Let me know I would surely get back to you with the results.


[Solved]: Gonna loose my job today !!! default controller redirecting url http://domain.com to http://www.domain.com. Wh - El Forum - 09-29-2007

[eluser]Derek Allard[/eluser]
The index calls everything, so this doesn't reduce the problem to the index file.

You suggested earlier it might be a route issue... what routes do you have? If I were you, I'd run a site-wide search for http://domian and see if I could find anything to help narrow down where that might be coming from.