www.webdeveloper.com
Results 1 to 2 of 2

Thread: New host ignores rewrite rule... why?

  1. #1
    Join Date
    Aug 2011
    Location
    near Sacramento, CA
    Posts
    50

    New host ignores rewrite rule... why?

    I'm moving a working site to a new host, and I've got a puzzling problem with URL rewrite rules.

    The new host is giving me 404's when I try to load a page that requires rewriting. It appears to be simply ignoring the rewrite rule.

    For example, the URL http://www.mysite.com/list-Topics-OMH should be rewritten to http://www.mysite.com/list.php?Topics=OMH. On the old host, it is; on the new host, it isn't.

    I've spoken to the new host's tech support about this. They've confirmed that the htaccess file is working in other respects (and I've since confirmed this myself). They say it must be a programming problem, not a system problem.

    They speculated that it's due to some difference in the way the rewrite module works between the version of Apache on my development system (2.2.17) and their version (2.2.22). That seems unlikely to me, but I don't know what else to suspect.

    Here's the contents of the htaccess file:

    Code:
    RewriteEngine on
    Options FollowSymLinks
    #RewriteBase is not needed because we are not rewriting the directory name.
    #This rule transforms "list-t-key" to "list.php?t=key".
    RewriteRule ^list-(.*)-(.*)$ list.php?$1=$2
    Any suggestions? If it's something weird in htaccess, how can I find it? If not, how might I prove that and force them to look farther?

  2. #2
    Join Date
    Aug 2011
    Location
    near Sacramento, CA
    Posts
    50
    Tech support turned out to be right: it was a bug.

    This was a classic case of looking failing to solve a problem by approaching it logically when the cause was completely off the wall.

    While trying to localize a bit of puzzling behavior that appeared to be only vaguely related to the problem, I ran across a PHP class method that was defined like this:

    Code:
    public public function name(arg,arg,arg) {
       . . . 
    }
    I fixed this, and everything started working.

    Here's where I went wrong:

    Wrong assumption #1: it works on the old site, so it must be correct.

    The version of PHP running on the old site simply ignored this bug. So did the version on my development system and the syntax checker in my IDE. But that didn't make it any less fatal.

    Wrong assumption #2: the symptom points to the problem.

    The symptom was a 404 error that listed the un-rewritten URL as the page that was not found. This led me to assume that mod_rewrite wasn't working. In fact it was working perfectly, but when the script at the rewritten URL was loaded, it got a syntax error. I don't know how that caused a 404 error, and may never know.

    The server's error log would have shown me exactly what was happening... if the symptom had given me any reason to look at it.

    I can't say I learned anything new here, but I re-learned a very old lesson: when things don't work, question every assumption you made... particularly the ones you didn't know you made!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles