为什么在这种情况下我无法在htaccess中重定向?

时间:2013-02-05 16:31:57

标签: apache .htaccess

我想使用htaccess:

重定向javascript文件的url

自:

http://www.domain.co.uk/tracking/tracking.js 

要:

http://www/domain.co.uk/Templates/domain.co.uk/tracking/tracking.js

在尝试了很多东西之后,现在我就是这个:

RewriteEngine on
RewriteRule tracking/tracking.js? http://www.domain.co.uk/Templates/domain.co.uk/js/tracking.js [L]

问题是,通过这种配置,我只能访问javascript代码(文件)写入........ / tracking / tracking.js /(最后用斜线,但我不想要它)

1 个答案:

答案 0 :(得分:1)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.domain\.co\.uk)$ [NC]
RewriteRule ^(tracking/tracking\.js)$ http://%1/Templates/domain.co.uk/$1 [L,R=301,NC]