我试图创建一个从http://example.com/links/AAA
到http://links.example.net/l/AAA
(其中AAA
是一个变量)的重定向。我有这个工作。问题是http://example.com/links/
和http://example.com/links
应该重定向到http://links.example.net
(没有/l/
)。.htaccess跨域重定向
此刻http://example.com/links/
重定向到http://links.example.net/l/
和example.com/links
重定向到http://links.example.net/l//hsphere/local/home/username/example.com/links
。
当前.htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} (.+)$ [NC]
RewriteRule ^(.*)$ http://links.example.net/l/$1 [R=301,L]
</IfModule>
伪代码:
if ($path) {
goto(http://links.example.net/l/${path}/); // Adding the trailing slash is not necessary, but would be handy. Obviously, don't add if it already exists.
} else {
goto(http://links.example.net/);
}
我走过一堆其他.htaccess
问题在这里看着(好伤心有这么多),但还没有找到任何等价。
如果需要,我可以做到这一点不同的方式:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1
</IfModule>
,然后执行重定向在PHP中,在那里我是有点多在家里。但是那样会(a)效率较低,(b)乐趣较少,以及(c)教育程度较低。所以我会试着以正确的方式做到这一点。
谢谢。我会在明天早上尝试第一件事并回报给你。 – TRiG