Rewrite URLS but .htaccess is giving me trouble. Not Sure wh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcc_shane
Forum Newbie
Posts: 22
Joined: Sat May 12, 2012 1:47 pm

Rewrite URLS but .htaccess is giving me trouble. Not Sure wh

Post by mcc_shane »

Hi Everyone,

I'm getting an internal server error when I add the .htaccess file. When I delete the file from my folder the URLS are working but when I add it I'm getting the below error. I'm attempting to rewrite my URLS. I'm trying to make them more SEO friendly. I'm trying to append the $city name from my MySql database onto my URL. Below is the error code and syntax for my pages.
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@whatsmyowncarworth.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at whatsmyowncarworth.com Port 80
As of right now I'm attempting to echo $city; to see if my coding is working but I wasn't expecting a internal servor problem. Any thoughts? Thanks for everyones help!

http://whatsmyowncarworth.com/auto/cars.php
http://whatsmyowncarworth.com/auto/Albany <<--- I'm trying to append city names within my URLS
http://whatsmyowncarworth.com/auto/Boston
http://whatsmyowncarworth.com/auto/Massachusetts

cars.php

Code: Select all

<?php 
ob_start(); // handle redirects

include('init.php'); // connection to database

if (isset($_GET['u']))
{
  $city = mysql_real_escape_string($_GET['u']); 
  
  if (ctype_alnum($city)) // protection against mysql injection
  {
    $data + mysql_query("SELECT State, City FROM cars WHERE City='$City'" );
	if (mysql_num_rows($data===1))
	{
	 echo $city;
	}
  }
}
?>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Code: Select all

.htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . * - [L]
RewriteRule ^(.*)$ http://whatsmyowncarworth.com/auto/cars.php?u=$1 [NC]
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Rewrite URLS but .htaccess is giving me trouble. Not Sur

Post by requinix »

1. Can I assume you didn't actually put ".htaccess file" in the file? Just in the post?
2. There's an extra space in your first RewriteRule.
Post Reply