Page 1 of 1

[SOLVED!] Pretty URLs causing 404s following server move

Posted: Wed Jan 14, 2009 3:49 pm
by Deak
We've moved our CMSMS site from one web host to another. Everything works beautifully, but only if we don't use pretty URLs. Which has me thinking there's a issue either with mod_rewrite on the host, config.php, or the .htaccess file.

1. Issue with mod_rewrite
I don't believe it is this as we have another customer site running on the same server (built using SilverStripe), where the URL rewriting works perfectly.

2. Issue with config.php
There's a few gotchas I'm aware of with this especially since we're currently hosting the site on an IP address (I want to get it all working on the IP before I repoint the DNS). However, I have set root_url to be the IP address + /~websitename. When I mouse over a link, this appears to have worked great; the paths and hierarchy are fine, just when you click you get a 404.

3. Issue with .htaccess
I've used the one from the wiki (here), which worked fine previously.

The Apache logs, however tell me something a bit more interesting:
[Wed Jan 14 14:18:19 2009] [error] [client 213.208.100.91] File does not exist: /var/www/html/home, referer: http://myserverip/~websitename/
[Wed Jan 14 14:18:19 2009] [error] [client 213.208.100.91] File does not exist: /var/www/html/404.shtml, referer: http://myserverip/~websitename/
The path it's talking about (/var/www/html/) is from the old server, not the new one. Is this info set somewhere in CMSMS? I can't see it in config.php. Is this even the problem?

Thanks a lot for your help!

Environment:
CMSMS version 1.4
PHP 5.2.x
Apache 2.x
CentOS

Re: Pretty URLs causing 404s following server move

Posted: Wed Jan 14, 2009 6:57 pm
by Nullig
The paths come from the config.php file - make sure they reflect the new setup. If you're not sure, you could do a fresh install to a subdirectory on the new server, using a different db prefix, to see what path settings are determined by the setup program.

Nullig

Re: Pretty URLs causing 404s following server move

Posted: Thu Jan 15, 2009 9:24 am
by Deak
Hi Nullig, thanks for the tip but I don't think what you describe is the issue. I've searched config.php for the old server path of "/var/www/html" and there's nothing, no mention of it at all.

All of the server paths appear correct:

$config['root_path'] = '/home/colony101/public_html';
$config['previews_path'] = '/home/colony101/public_html/tmp/cache';
$config['uploads_path'] = '/home/colony101/public_html/uploads';
$config['image_uploads_path'] = '/home/colony101/public_html/uploads/images';

Where on earth could that path be coming from?!

Re: Pretty URLs causing 404s following server move

Posted: Thu Jan 15, 2009 10:11 pm
by Dr.CSS
So you did a fresh install in a subfolder and it says the same paths as the config in the problem site?...

Re: Pretty URLs causing 404s following server move

Posted: Fri Jan 16, 2009 11:28 am
by Deak
Hi Mark,

Okay, I admit I hadn't done that. I think I smelt victory and went for a short cut! Lesson learned. :)

However, I now have done as Nullig and yourself have suggested. There was indeed a small difference in the server paths:

My actual config.php's paths are:
/home/colony101/public_html

This new test install has paths saying:
/home/colony101/domains//public_html/

So, I took the newly made config.php and used it for my actual site on the new server, making appropriate changes. (I amended the server paths, just ditching the sub-directory I installed to; I also changed the database configuration appropriately and set assume_mod_rewrite to true and use_hierarchy to true).

I still get 404s when I click on any links.

Apache's error log says:
[Fri Jan 16 11:12:58 2009] [error] [client myip] File does not exist: /var/www/html/home, referer: http://ourserveripaddress/~colony101/
[Fri Jan 16 11:12:58 2009] [error] [client myip] File does not exist: /var/www/html/404.shtml, referer: http://ourserveripaddress/~colony101/
Where the heck is it getting those old server paths from?! Argh!

However, this may be of interest...

In the brand new test site, I enabled mod_rewrite and hierarchical URLs. It also throws 404s...

Apache says:
[Fri Jan 16 11:22:28 2009] [error] [client myip] File does not exist: /var/www/html/home, referer: http://ourserveripaddress/~colony101/websitetest/
[Fri Jan 16 11:22:28 2009] [error] [client myip] File does not exist: /var/www/html/404.shtml, referer: http://ourserveripaddress/~colony101/websitetest/
I am now wondering if my host has screwed up my httpd.conf or something? In trying to get this thing to work as per the old server, I emailed them the old server's httpd.conf and said "here's the modules etc as per the old environment". I can't believe they would have copy/pasted paths from another server...

Am I even thinking in the right direction?

Re: Pretty URLs causing 404s following server move

Posted: Fri Jan 16, 2009 11:43 am
by Deak
So I guess this fresh test install of CMSMS on the server officially rules out two of my initial suggestions?

2. Issue with config.php
Since we have a brand new config.php made from the new install.

3. Issue with .htaccess
Has only standard content from CMSMS wiki:
Options +FollowSymLinks
RewriteEngine on

# 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]

Re: Pretty URLs causing 404s following server move

Posted: Mon Jan 19, 2009 1:19 pm
by Deak
A little update, in case anyone's still reading. :)

I've posted the Apache error log, but here, in addition, is the error the browser shows:
Not Found

The requested URL /home/colony101/public_html/index.php was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Which is interesting as the first part would appear to be a separate problem from the 404.

I'm getting a little bit desperate with this one since it's costing me money to keep my old server running. Argh!

Re: Pretty URLs causing 404s following server move

Posted: Tue Jan 20, 2009 1:38 pm
by Deak
I'm now fairly convinced this is a CMSMS configuration issue unrelated to my site or a server issue specific to CMSMS.

1. A fresh/empty CMSMS install to a sub-directory has all the same problems.

2. Installing SilverStripe to sub-directory and creating some pages to test mod_rewrite and SEO friendly URLs works fine.

I think I've hit the wall with this one.

Re: Pretty URLs causing 404s following server move

Posted: Wed Jan 21, 2009 12:55 pm
by Deak
Thank goodness; this is finally solved!

Here's a breakdown of the issue.

We moved the website to a new server, running it off of the IP address whilst we double-checked the configuration (before re-pointing our DNS to the new server). So we were running off of an IP like thus:

http://ournewserveripaddress/~websitename

The issue was the .htaccess, which had:
RewriteBase /


Except, of course, and it's obvious now, it shouldn't rewrite the URL all the way back to the base of the IP in this instance, since the ~/ pointed to a folder where CMSMS lived. Amending the .htaccess as below fixed it:
RewriteBase /~websitename/
So I think we're good to flick RewriteBase back to the / and repoint the DNS, then kill the old server.

Re: [SOLVED!] Pretty URLs causing 404s following server move

Posted: Thu Jan 22, 2009 1:25 am
by Dr.CSS
Yes if you are using .htaccess mod_rewrite rules and it is in a sub folder of root you need to put the RewriteBase /name of folder in...

Re: [SOLVED!] Pretty URLs causing 404s following server move

Posted: Thu Feb 26, 2009 4:57 pm
by trucmuche
Hi Deak.
I had exactly the same problem, I spent hours on it searching the board, testing and... you solved it !
I've just registered here to say : THANK YOU THANK YOU THANK YOU !
:)

Cheers !

Re: [SOLVED!] Pretty URLs causing 404s following server move

Posted: Tue Mar 17, 2009 12:24 pm
by Deak
trucmuche wrote: Hi Deak.
I had exactly the same problem, I spent hours on it searching the board, testing and... you solved it !
I've just registered here to say : THANK YOU THANK YOU THANK YOU !
:)

Cheers !
Wow, first time I ever solved anything. I usually just create problems. :)