.htaccess rule:将参数重定向到filename

时间:2016-11-17 13:06:14

标签: apache mod-rewrite

如何重定向以下示例:

http://www.mypage.tld/media/optivo/ch/de/?id=0805610075C6000

http://www.mypage.tld/media/optivo/ch/de/0805610075C6000.xml

因此参数值应为扩展名为.xml的文件名

我试过了:

RewriteCond %{QUERY_STRING} (?:^|&)id=([^&]+)  
RewriteRule ^media/optivo/ch/de/$ $0%1.xml [L,R=permanent]

1 个答案:

答案 0 :(得分:0)

RewriteEngine on

# capture the value of id parameter
RewriteCond %{QUERY_STRING} (?:^|&)id=([^&]+)
# for a .htaccess in root directory
RewriteRule ^media/optivo/ch/de/(?:index\.php)?$ $0%1.xml [L,R=permanent]
# for a .htaccess located in de subdirectory
#RewriteRule ^(?:index\.php)?$ %{REQUEST_URI}%1.xml [L,R=permanent]