JGK
JGK

Reputation: 138

How to Remove Query String in Dynamic url in PHP

I have dynamic url like

http://epathasala.com/schooldetails.php?name=john-paul-higher-secondary-school
http://epathasala.com/universitydetails.php?name=demo-university
http://epathasala.com/schooldetails.php?name=tagore-international-school

I need to remove all the query string and change the url like below


    http://epathasala.com/collegedetails/gtn-arts-college
    http://epathasala.com/universitydetails/demo-university
    http://epathasala.com/schooldetails/tagore-international-school

I have tried [Pretty URL - mod_rewrite question][1] But not working. Please some one help. Thanks

I have tried this below htaccess code but its not working.

RewriteEngine On
RewriteBase /
RewriteRule ^epathasala/schooldetails/(.*)$ /epathasala/schooldetails.php?name=$1 [NC,L]

I need to remove this part ".php?name=" from the url.

Upvotes: 2

Views: 426

Answers (2)

RewriteRule ^(.*?)/(.*?)/?$ $1.php?name=$2 [NC,L]

Upvotes: 1

Amit Verma
Amit Verma

Reputation: 41219

This should work :

RewriteEngine On
RewriteBase /
RewriteRule ^epathasala/([^/]+)/([^/]+)/?$ /epathasala/$1.php?name=$2 [NC,L]

Upvotes: 0

Related Questions