将子域重定向到特定文件而不是文件夹

时间:2012-03-16 16:15:25

标签: .htaccess

假设我的网站上有这样的文件:

example.com/pages/live_report.php

现在我想要当用户输入网址 live.example.com 时,它会引用上面的文件而不会强制重命名它。

我怎么能通过htaccess做到这一点?

当然我尝试在Redirect a subdomain to a directory using .htaccess上推荐这条规则:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.example\.com
RewriteRule ^(.*)$ /pages/live_report.php$1 [L]

但这不起作用

2 个答案:

答案 0 :(得分:2)

如果它根本不起作用,那么很多人在vhost文件中没有'AllowOverride All'。尝试像

这样的东西
deny from all

查看.htaccess是否正在处理

如果您被重定向到http://live.example.com/pages/live_report.php,则需要使用完整的URI,例如

RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.example\.com
RewriteRule ^(.*)$ http://www.example.com/pages/live_report.php$1 [L]

答案 1 :(得分:0)

也许这会有所帮助(未经测试):

RedirectMatch 301 ^/folder http://www.mydomain.com/file.html

或者这个:

RedirectMatch 301 ^/folder(.*) http://www.mydomain.com/file.html
相关问题