【问题标题】:redirecting from short url从短网址重定向
【发布时间】:2012-08-16 15:05:44
【问题描述】:

假设 short.com 是短域,long.com 是长域

更新:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.long.com
RewriteRule (.*) http://long.com/ [R=301]

RewriteCond %{HTTP_HOST} ^short\.li$ [NC]
RewriteCond %{REQUEST_URI} !^/redirect
RewriteRule ^(.*)$ /redirect?short=$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)short\.li$
RewriteRule ^$ http://long.com/ [L,R=301]

两个域都指向该根目录。当我输入 short.li 时,我最终会访问 long.com/?l= 我是怎么搞成这样的?^^

【问题讨论】:

  • 需要更多关于您当前实施的信息才能给出准确的答案。您当前的 .htaccess 代码会很好。

标签: .htaccess url redirect


【解决方案1】:

在你的 htaccess 文件中试试这个:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)short\.com$
RewriteRule ^$ http://www.long.com/ [L,QSA,R=301]

如果RewriteEngine on 已经存在,则删除它

【讨论】:

  • 如何将它与redirect.php 条件合并? RewriteCond %{HTTP_HOST} ^short\.com$ [NC] RewriteCond %{REQUEST_URI} !^/redirect RewriteRule ^(.*)$ /redirect?short=$1 [L]
  • 我不知道如何在这里换行-.-
  • 我只是合并了这 2 个。我到底怎么会得到:long.com/?l= 当去 short.com 时?
  • 我不明白你在这里写什么,请用新代码编辑你的问题
【解决方案2】:

我想你可能想要这样的东西:

RewriteEngine on
RewriteCond {REQUEST_URI} !/
RewriteCond {HTTP_HOST} short.com
RewriteRule ^(.*) http://long.com/redirect.php?short=$1 [L,R=301]

RewriteCond {REQUEST_URI} /
RewriteCond {HTTP_HOST} short.com
RewriteRule ^(.*) http://long.com/ [L,R=301]

不确定最后一个是否需要正则表达式,但这样的东西应该可以工作

【讨论】:

  • 其实……没关系。我认为我的第一个条件不会起作用,因为它会跳过 URL 代码。 Yazmat 的回答更好。
猜你喜欢
  • 1970-01-01
  • 2018-08-17
  • 2013-02-19
  • 2021-10-21
  • 1970-01-01
  • 2012-10-13
  • 1970-01-01
  • 2021-06-22
  • 1970-01-01
相关资源
最近更新 更多