用参数 htaccess 重写动态 url
Rewrite dynamic url with parameter htaccess
我有动态 url :
example.com/folder1/{dynamic number}/folder2?api=apikey&page=1
哪个是数字{dynamic number}是任意数字
例如:
example.com/folder1/123/folder2?api=apikey&page=1
我从来没有文件夹“123”,因为它是动态的 url
最终结果为example.com/myfolder?id=123&api=akipkey&page=1
我试过了
RewriteRule ^folder1/([0-9]+)/folder2/ /myfolder?id=&api=akipkey&page=1
结果example.com/folder1/myfolder?123
将以下 htaccess 规则放在 htaccess 规则文件的顶部。请确保在测试您的 URL 之前清除您的浏览器缓存。
还要确保您的 htaccess 文件位于 myfolder folder/directory 之外(不在其旁边)。
RewriteEngine ON
RewriteBase /folder1/
##Rule for external rewrite to match url like: http://localhost:80/folder1/123/folder2?api=apikey&page=1 goes here.
RewriteCond %{THE_REQUEST} \s/(?:[^/]*)/(\d+)/folder2\?(\S+)\s [NC]
RewriteRule ^ myfolder?id=%1&%2 [R=301,L]
##Rules for internal rewrite to index.php here...
RewriteCond %{THE_REQUEST} \s/myfolder\?id=(\S+)\s [NC]
RewriteRule ^ folder1/myfolder/index.php?id=%1 [QSA,L]
#####Rest of your htaccess Rules goes after this one....
我有动态 url :
example.com/folder1/{dynamic number}/folder2?api=apikey&page=1
哪个是数字{dynamic number}是任意数字
例如:
example.com/folder1/123/folder2?api=apikey&page=1
我从来没有文件夹“123”,因为它是动态的 url
最终结果为example.com/myfolder?id=123&api=akipkey&page=1
我试过了
RewriteRule ^folder1/([0-9]+)/folder2/ /myfolder?id=&api=akipkey&page=1
结果example.com/folder1/myfolder?123
将以下 htaccess 规则放在 htaccess 规则文件的顶部。请确保在测试您的 URL 之前清除您的浏览器缓存。
还要确保您的 htaccess 文件位于 myfolder folder/directory 之外(不在其旁边)。
RewriteEngine ON
RewriteBase /folder1/
##Rule for external rewrite to match url like: http://localhost:80/folder1/123/folder2?api=apikey&page=1 goes here.
RewriteCond %{THE_REQUEST} \s/(?:[^/]*)/(\d+)/folder2\?(\S+)\s [NC]
RewriteRule ^ myfolder?id=%1&%2 [R=301,L]
##Rules for internal rewrite to index.php here...
RewriteCond %{THE_REQUEST} \s/myfolder\?id=(\S+)\s [NC]
RewriteRule ^ folder1/myfolder/index.php?id=%1 [QSA,L]
#####Rest of your htaccess Rules goes after this one....