Ok. I have ZERO PHP Knowledge, still good in editing php and all that stuff. Only know copy paste and have no knowledge what that means. Still would try to explain my problem.

I use variable to fetch data from mysql. Ex. my url is http://www.example.com/venue.php?vcity=New York.

Now, I want to replace New York with New-York. The real url I am trying to get is http://www.example.com/venue-new-york.php.

For that I added code in htaccess

RewriteRule ^venue-([^/]*)\.php$ /venue.php?vcity=$1 [L]

I Know what I added in htaccess is mostly perfect.

Now, I am using smarty so would be able to do lower case and replace space with dash. But that would not allow me to fetch data from mysql for some reason. In class file I have following code.

function getallvenueschedule()
	{
		global $db,$smarty;
		$sql = " SELECT * FROM table WHERE vcity = '$this->vcity' AND sch_date >= '$this->sch_date' ORDER BY timestmp ASC";
		$theList	= $db->getAll($sql); 
		return $theList;
	}

In the venue.php file below is code.

$vcity = $_GET['vcity'];

Why not use the MySql REPLACE() command in your query:

SELECT *, REPLACE(vcity, ' ', '-') AS vcity_replaced FROM table WHERE vcity = '$this->vcity' AND sch_date >= '$this->sch_date' ORDER BY timestmp ASC

It might be possible to do in your htaccess, but that would require a regex that specifically targets each space, am not sure how that could be done, since you don't know how many there are going to be. You could match them, but am not sure how to replace them.

Why not use the MySql REPLACE() command in your query:

SELECT *, REPLACE(vcity, ' ', '-') AS vcity_replaced FROM table WHERE vcity = '$this->vcity' AND sch_date >= '$this->sch_date' ORDER BY timestmp ASC

It might be possible to do in your htaccess, but that would require a regex that specifically targets each space, am not sure how that could be done, since you don't know how many there are going to be. You could match them, but am not sure how to replace them.

Hi,

What should replace "vcity_replaced" as ?

Moreover, will I need to change venue.php file for that purpose.

I don't have more than two spaces in venue (usually only one space). So if htaccess works, i would accept it as of now, if no solution comes.

I think this would work for one space:

RewriteRule ^venue-([^/ ]*)( ?)([^/ ]*)\.php$ /venue.php?vcity=$1-$3 [L]

I am not sure yet how to fix it for more.

I am not sure yet how to fix it for more.

Ok. Any idea if same can work without htaccess. I am missing just something. (I have sent you PM also)

Solved in other way.

Actually no trick worked.

But what happen that url still work with "+" sign between two words (or say replace space with +).

I would not mind that "+" sign.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.