缩短网址只包含获取请求?

时间:2016-01-07 10:42:23

标签: php html apache .htaccess http

如何制作,以便我的网页重定向网址:https://mysite/12345https://mysite/image.php?id=12345

我希望能够缩短网址,只包含get请求。这可以通过php或.htaccess文件实现吗?

1 个答案:

答案 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]