【问题标题】:How do I redirect a long url to a short one but serve the long url to the client?如何将长网址重定向到短网址,但将长网址提供给客户端?
【发布时间】:2021-11-16 13:57:15
【问题描述】:

我网站的 URL 格式为...

www.website.com/index?t=abc123

...abc123 是一个 6 个字符的十六进制代码。如何使用 htaccess 将所有这样的地址重定向到...

www.website.com/abc123

...但仍以原始 URL 提供内容?

因此,例如,键入...

www.website.com/index/php?t=5f33ee

...将重定向到...

www.website.com/5f33ee

...但会提供来自...的内容

www.website.com/index.php?t=5f33ee

...没有用户被重定向。

到目前为止,我的 .htaccess 看起来像这样。我理解,第一点将所有非 https 流量重定向到 https。第二个 RewriteRule 似乎可以从短 url 提供内容。

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
RewriteRule ^(.*)$ https://www.website.com/$1 [R=301]
RewriteRule ^([0-9a-f]{6})$ index.php?t=$1 [L]

【问题讨论】:

标签: apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

用这些规则解决。

RewriteCond %{QUERY_STRING} !x
RewriteCond %{QUERY_STRING} t=([0-9a-f]{6})
RewriteRule ^/?index\.php$ /%1? [R=301,L]
RewriteRule ^/?([0-9a-f]{6})$ /index.php?x&t=$1 [QSA,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-28
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多