【发布时间】:2012-07-31 05:40:50
【问题描述】:
如何将 .aspx 网址重定向到 php 页面? 我有来自我的旧站点的链接 domain.com/song.aspx?SongID=1 我想重定向到 domain.com/song.php?SongID=2 文件。你能告诉我怎么做吗? 我愿意使用 htaccess 或插件。如果我使用插件,我需要能够让 song.php 也能在 song.aspx 之后获取查询字符串。
【问题讨论】:
如何将 .aspx 网址重定向到 php 页面? 我有来自我的旧站点的链接 domain.com/song.aspx?SongID=1 我想重定向到 domain.com/song.php?SongID=2 文件。你能告诉我怎么做吗? 我愿意使用 htaccess 或插件。如果我使用插件,我需要能够让 song.php 也能在 song.aspx 之后获取查询字符串。
【问题讨论】:
Htaccess 可能是最好的方法。这条规则很笼统,但应该可以解决问题。
RewriteRule ^song\.aspx$ song.php [R=301,QSA,L]
QSA 代表“Query String Append”,它将查询字符串从旧 URL 附加到新 URL。
【讨论】:
如果您需要匹配查询字符串并更改 ID,例如您的示例:
domain.com/song.aspx?SongID=1 我想重定向到 domain.com/song.php?SongID=2
您需要为此设置一个重写列表:
RewriteCond %{QUERY_STRING} ^SongID=1$
RewriteRule ^/?song\.aspx$ /song.php?SongID=2 [R=301,L]
【讨论】: