简体   繁体   English

301将动态网址重定向到重写的网址

[英]301 Redirect dynamic url to a rewrited url

I want to redirect all dynamic links to redirect to its rewritten url eg: 我想重定向所有动态链接以重定向到其重写的URL,例如:

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

to

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

My htaccess: 我的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 尝试了很多我没有任何解决方案,请帮助,在此先感谢

Try this in your htaccess : 在您的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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM