Forum Moderators: phranque

Message Too Old, No Replies

Weird .htaccess problem

Site not displaying properly at new host

         

swaz

7:06 am on Nov 19, 2007 (gmt 0)

10+ Year Member



I moved my site to another host recently and the pages are not displaying properly. All the individual pages eg : carddetail.php and list_cards.php are showing ALL the cards in the database instead of only specific cards.

http://www.example.com/credit-card-applications/card-id/1 - Individual Pages
http://www.example.com/find-credit-cards/good-credit/1 - Category pages

The site was working fine on the old host. The transfer was done using WHM so I don't think any files could have gone missing in the process. I checked the .htaccess files at the old and new host, and the content are the same.

I asked the new host if Options +FollowSymLinks is enabled and they replied yes. I tried removing Options +FollowSymLinks from the .htaccess file but it did not make a difference.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^article-detail article-detail.php
RewriteRule ^credit-card-applications carddetail.php
RewriteRule ^contact contact.php
RewriteRule ^news-detail news-detail.php
RewriteRule ^find-credit-cards list_cards.php
RewriteRule ^search search.php

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

Can you guys help me with this problem?

[edited by: jdMorgan at 11:55 am (utc) on Nov. 19, 2007]
[edit reason] example.com [/edit]

jdMorgan

12:17 pm on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code is quite problematic, in that it shows a high probability of rewrite looping, and the order of the internal rewrite and external redirect blocks is reversed, exposing your internal URL-paths to requests for 'domain.com'

If your script uses certain internal server variables, then rewrite looping could cause it to operate incorrectly.

Since I don't know how your scripts work, I cannot tell if looping is the cause of your problem, but I'd suggest the following changes:


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^article-detail article-detail.php [L]
#
RewriteRule ^credit-card-applications carddetail.php [L]
#
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^contact contact.php [L]
#
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^news-detail news-detail.php [L]
#
RewriteRule ^find-credit-cards list_cards.php [L]
#
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^search search.php [L]

This moves the domain canonicalization redirect ahead of the internal rewrites, and prevents your URL-paths ending in ".php" from being rewritten to themselves. This latter step is only needed where the script's URL-path exactly matches the 'friendly' URL prefix, as shown. I also added [L] flags for improved efficiency.

There are several ways to prevent this rewrite looping. The above is the brute-force method. You could do this in several ways, but I show the simplest, most straightforward method here.

Jim

swaz

12:57 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



Thanks for your help Jim but the code you gave didn't work either. The individual card pages and categories pages are still displaying all cards in the database.

The redirect from non www to www is the only thing that works.

I'm at loss on what to do as the site is displaying fine in the old host but not at the new host.

jdMorgan

1:08 pm on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check the new and old host Apache versions. It looks to me as though your script depends on AcceptPathInfo being enabled, and that is only available on Apache 2.x

If both servers are Apache 2.x, then make sure AcceptPathInfo is enabled on the new host. See Apache 2.x core docs for more info on this directive.

Jim

swaz

1:37 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



Both hosts are running 1.3.39 (Unix).

Do I still need to check if AcceptPathInfo is enabled?

jdMorgan

2:38 pm on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, AcceptPathInfo is only available on Apache 2.x

I'm out of ideas for now. :(

Jim

swaz

3:21 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



It's alright. Thanks for all the help!

jdMorgan

10:19 pm on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might want to look at the script, and determine what mechanism and server variables it uses to 'catch' the requested URL-path. Then modify it to 'echo' those variables and compare the results on both servers. It may then be possible to determine what the problem is, and modify the script to use a more universal/portable method.

Jim

swaz

6:11 am on Nov 20, 2007 (gmt 0)

10+ Year Member



Sorry I'm a noob when it comes to php etc. I bought the site from someone last year actually and he modified the script, so there are new and old files on the server.

Anyway I took a look at the script and found this


<?
function display_card($card_array)
{
?>

As a last resort, can you recommend me anyone who might know the solution? I'm willing to pay.