【问题标题】:rewrite url that works like tinyURL in htaccess [closed]在 htaccess 中重写与 tinyURL 类似的 url [关闭]
【发布时间】:2015-06-05 09:47:13
【问题描述】:

我想重定向我的示例网址,如下所示

https://example.com/r6KmjN
https://example.com/Q8w4d9
https://example.com/s8I2n2

结束字符不会相同,而是 6 个字符

 https://example.com/tinyurl.php?id=r6KmjN
 https://example.com/tinyurl.php?id=Q8w4d9
 https://example.com/tinyurl.php?id=s8I2n2

这可能吗?如果您能帮助我解决这个问题,我们将不胜感激。谢谢

【问题讨论】:

  • 我投票结束这个问题作为离题,因为它是一个骗子的骗子的骗子的骗子的骗子的骗子的骗子的。去找一个适合你需要的骗子。
  • 这肯定是重复的。你要找的是mod_rewrite
  • mod_rewrite的可能重复

标签: php regex .htaccess tinyurl


【解决方案1】:

在你的 /.htaccess 中试试这个:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ http://example.com/tinyurl.php?id=$1 [QSA,NC,L] 

如果您想将其用于内部重定向,请从目标 url 中删除主机名和方案

【讨论】:

  • 这部分工作并帮助我找到了解决方案。谢谢 Starkeen
  • 这符合我的预期。这不是题外话,因为这是唯一的,我正在检查文件夹的总字符数 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([ ^/]{5}+)/?$ index.php [QSA,NC,L]
猜你喜欢
  • 2021-03-22
  • 2012-01-12
  • 2013-12-25
  • 1970-01-01
  • 1970-01-01
  • 2021-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多