Jebastin Franklin
Jebastin Franklin

Reputation: 101

301 Redirect dynamic url to a rewrited url

I want to redirect all dynamic links to redirect to its rewritten url eg:

http://www.example.in/ads-detail.php?location=Mumbai&id=37&name=sudha-restaurant

to

http://www.example.in/Mumbai/37/sudha-restaurant

My htaccess:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /ads-detail.php?location=$1&id=$2&name=$3 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]*)/([^/]*)$ /ads-detail.php?id=$1&name=$2 [QSA,L] –

Tried alot i haven't got any solution please help , Thanks in advance

Upvotes: 1

Views: 70

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

Try this in your htaccess :

 RewriteEngine on
#1) redirect "/ads-detail.php?location=foo&id=123&name=bar" to "/foo/123/bar"
RewriteCond %{THE_REQUEST} /ads-detail.php\?location=([^&]+)&id=([^&]+)&name=([^\s]+) [NC]
RewriteRule ^ /%1/%2/%3? [NC,L,R]

#2) if the requested  is not for an existing directory
RewriteCond %{REQUEST_FILENAME} !-d

 #3) then rewrite "/foo/123/bar" to "ads-details.php"
 RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /ads-detail.php?location=$1&id=$2&name=$3 [NC,L]

Upvotes: 1

Related Questions