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

时间:2015-11-25 12:42:06

标签: php .htaccess mod-rewrite url-rewriting

我想重定向所有动态链接以重定向到其重写的网址,例如:

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

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

我的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] –

尝试很多我没有任何解决方案,请帮助,提前致谢

1 个答案:

答案 0 :(得分:1)

在你的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]