Link to home
Start Free TrialLog in
Avatar of nccguys
nccguys

asked on

Help with mod_rewrite on GoDaddy

I am testing my software on GoDaddy's servers and it is functioning very strange.
 
This software works okay on other 'LAMP' type servers with mod_rewite installed.  GoDaddy is not offering any helpful support on this.  They just state that they are using the 'normal' apache mod_rewrite module.

The software is PHP/mySQL based and is pulling the 'directory' name (ie. classified, contact, help) from fields in the database.

Here is what's strange. It does not work with some directives in lower case.  

Broke: http://demo4.topclassifiedsoftware.com/classified/Cars-vehicles
Works: http://demo4.topclassifiedsoftware.com/Classified/Cars-vehicles
** Notice the uppercase C in /Classified

Broke: http://demo4.topclassifiedsoftware.com/contact
Works: http://demo4.topclassifiedsoftware.com/Contact
** Notice the uppercase C in /Contact. The url field 'contact' is in lowercase in the database.

Works: http://demo4.topclassifiedsoftware.com/help
Works: http://demo4.topclassifiedsoftware.com/Help
** Notice both of these work. The url field 'help' is in lowercase in the database.

I've attached a copy of my .htaccess .htaccess.txt
Avatar of Frank Contrepois
Frank Contrepois
Flag of United Kingdom of Great Britain and Northern Ireland image

Use the [NC] in your rewrite rules

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriteflags

RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?pid=$1 [NC]
RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2 [NC]
RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9_-]+)/?([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2&page=$3 [NC]
Avatar of nccguys
nccguys

ASKER

Just tried that, but same results.  Any other ideas?
Filesystems are case sensitive on Unix systems, so rename you files accordingly
Avatar of nccguys

ASKER

These are not files I'm browsing to, it's all database generated.

For example, the top navigation which contains links to the /contact and /help mentioned above are created by this command.

      $menu = mysql_query("SELECT * FROM cms_pages where menushow='1' order by weight asc") or die(mysql_error());
      $num_of_pages = mysql_num_rows($menu);      
      $cls = "top_menu";
      if($num_of_pages<=10){
            $cls = "top_menu1";
      }
Avatar of nccguys

ASKER

Also, on any of my other Linux servers, both these URLs work fine.

http://demo2.topclassifiedsoftware.com/Classified/Cars-vehicles
http://demo2.topclassifiedsoftware.com/classified/Cars-vehicles
** Notice the 'c' in /classified
Going back to basic

http://demo4.topclassifiedsoftware.com/classified/Cars-vehicles
is converted to
http://demo4.topclassifiedsoftware.com/index.php?pid=classified&mode=Cars-vehicles -> OK
http://demo4.topclassifiedsoftware.com/index.php?pid=CLASSified&mode=CARs-vehicles -> OK

so pid and mode are insensitive.

http://demo4.topclassifiedsoftware.com/Classified/CARS-vehicles -> OK
so only the first (pid) part of the Rewrite is having troubles

I cannot see any error on that line so here my next tries:
use /index.php?pid.... instead of index.php (without the initial /)
try the following line RewriteRule ^([ca-zA-Z0-9_-]+)/?([a-zA-Z0-9_-]+)/?$ to check for a rewrite bug on c letter (?_?)
another try RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2 (the in between / is needed)
another try remove the initial ^

but that's just guessing

Sorry for the last comment, it looks like any uppercase letter in the pid part got the thing to work
Last idea:
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/?$ index.php?pid=$1&mode=$2 [NC]

using the NC and removing A-Z
Avatar of nccguys

ASKER

Thanks for the help so far.  None of the combinations seem to be working.  Here's the last two I tried.


RewriteRule ^([a-z0-9_-]+)/?$ index.php?pid=$1 [NC]
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/?$ index.php?pid=$1&mode=$2 [NC]
RewriteRule ^([a-z0-9_-]+)/?([a-z0-9_-]+)/?([a-z0-9_-]+)/?$ index.php?pid=$1&mode=$2&page=$3 [NC]

RewriteRule ^([a-z0-9_-]+)/?$ /index.php?pid=$1 [NC]
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/?$ /index.php?pid=$1&mode=$2 [NC]
RewriteRule ^([a-z0-9_-]+)/?([a-z0-9_-]+)/?([a-z0-9_-]+)/?$ /index.php?pid=$1&mode=$2&page=$3 [NC]
just to try, use (.*) instead of ([a-z0-9_-]+)
Avatar of nccguys

ASKER

Might be on to something.  This 'kinda' works now.

I'm not getting any error messages, but the 'paths' are not pulling correctly.  Images and CSS aren't pulling.

Take a look now:
http://demo4.topclassifiedsoftware.com/classified/Cars-vehicles
try like this, just to investigate where the problem is

RewriteRule ^([a-z]+)/?([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2 [NC]
Avatar of nccguys

ASKER

No error message, but still no image/css

Here's the .htaccess now, just to make sure it looks right.

      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)/?$ index.php?pid=$1 [NC]
      RewriteRule ^([a-z]+)/?([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2 [NC]
    RewriteRule ^(.*)/?(.*)/?(.*)/?$ index.php?pid=$1&mode=$2&page=$3 [NC]
RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?pid=$1 [NC]
      RewriteRule ^([a-z]+)/?([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2 [NC]
    RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9_-]+)/?([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2&page=$3 [NC]


for now let's concentrate on the line
RewriteRule ^([a-z]+)/?([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2 [NC]
and the http://demo4.topclassifiedsoftware.com/classified/CARS-vehicles/ 
Avatar of nccguys

ASKER

RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?pid=$1 [NC]
RewriteRule ^([a-z]+)/?([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2 [NC]
RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9_-]+)/?([a-zA-Z0-9_-]+)/?$ index.php?pid=$1&mode=$2&page=$3 [NC]

Error / Not Found
http://demo4.topclassifiedsoftware.com/classified/Cars-vehicles

No Error, but no image/css
http://demo4.topclassifiedsoftware.com/Classified/Cars-vehicles
ASKER CERTIFIED SOLUTION
Avatar of Frank Contrepois
Frank Contrepois
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nccguys

ASKER

A little better now.  Most of the site is coming up now without errors.  Only the 'content' area is not being displayed.  What do you see on your end?
On ipad looks like it works
Avatar of nccguys

ASKER

I checked on iPhone and it looks the same as browser.  Take a look at http://demo2.topclassifiedsoftware.com to see what it should look like.

I see all of the 'template' area, just not content.
no more ideas for now :(
as you said it looks like a bug of rewrite module
Avatar of nccguys

ASKER

Well you got me a lot closer than before.  I'm going to award you the solution for this because we are not getting the error at least.  Thank you very much for the help with this!!