假设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=上 我是怎么设法搞砸的?^^
答案 0 :(得分:2)
在你的htaccess文件中试试这个:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)short\.com$
RewriteRule ^$ http://www.long.com/ [L,QSA,R=301]
删除RewriteEngine on
(如果已经存在)
答案 1 :(得分:0)
我想你可能想要一些与此类似的东西:
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]
不确定最后一个是否需要正则表达式,但这样的事情应该起作用