Wasim Khan
Wasim Khan

Reputation: 7

facing trobule in url-rewriting a dynamic url

I am using .htaccess file for URL re-writing and i change the some url like this using .htaccess file :-

RewriteRule  ^home/?$ index.php   [NC,L]

but i have no idea how i change this url

/localhost/mywebiste/complete_listing.php?category=Education&city=delhi

into this URL

/localhost/mywebiste/education-in-delhi

Every category and city in url.

i try this :

Rewrite-rule  ^Agriculture-in-jaipur([A-Za-z0-9-]+)?$ complete_listing.php?category=education&&city=delhi [NC,L]

but by this i change only one type URL every time category and city will be changed

Upvotes: 0

Views: 77

Answers (3)

Bruno Novais
Bruno Novais

Reputation: 29

That code will return http://www.example.com/Education-in-delhi.html

RewriteEngine On
RewriteRule ^([^-]*)-in-([^-]*)\.html$ /mywebiste/complete_listing.php?category=$1&city=$2 [L]

Upvotes: 0

Forien
Forien

Reputation: 2763

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)-in-(.*)$ complete_listing.php?category=$1&city=$2 [NC,L]

Upvotes: 1

violator667
violator667

Reputation: 499

If I'm right you want to get /localhost/mywebiste/education-in-delhi - the url with 2 variables

RewriteRule  ^([A-Za-z0-9-]+)-in-([A-Za-z0-9-]+)$ complete_listing.php?category=$1&city=$2 [NC,L]

Note the L on the end - this will be the Last rule applied.

Upvotes: 1

Related Questions