如何制作,以便我的网页重定向网址:https://mysite/12345到https://mysite/image.php?id=12345
我希望能够缩短网址,只包含get请求。这可以通过php或.htaccess文件实现吗?
答案 0 :(得分:2)
通常,您可以使用.htaccess
文件执行此操作,条目如下:
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)(/?)$ image.php?id=$1 [NC,L]
所以你可以用以下格式写你的网址:
https://mysite/12345
转而采用其他方式,并将https://mysite/image.php?id=12345
重定向到https://mysite/12345
等网址
RewriteCond %{THE_REQUEST} /(?:image\.php)?\?id=([^&\s]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]