如何使我的页面重定向如下网址:https://mysite/12345至https://mysite/image.php?id=12345
我希望能够缩短网址以仅包含获取请求。这可以通过 php 或 .htaccess 文件实现吗?
最佳答案
通常,您可以使用 .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]
关于php - 缩短 URL 以仅包含 get 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34653082/