【问题标题】:Shorten URL to only include get request?缩短 URL 以仅包含获取请求?
【发布时间】:2016-01-07 10:42:22
【问题描述】:

如何使我的页面重定向如下网址:https://mysite/12345https://mysite/image.php?id=12345

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

【问题讨论】:

    标签: php html apache .htaccess http


    【解决方案1】:

    通常您会使用 .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]
    

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 2018-05-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 2011-04-30
      • 1970-01-01
      • 2014-05-01
      • 1970-01-01
      相关资源
      最近更新 更多