子目录中的htaccess重定向到主域

时间:2016-06-22 15:09:27

标签: apache .htaccess mod-rewrite url-rewriting url-redirection

我对网址管理有以下规则,将非www流量重定向到www,然后重写一些网址。它似乎工作正常,除非我去" http://example.com/prosite/" (没有www,第一个重定向案例 - " ^ $")。我希望这会带来主页(意味着它应该重定向到http://www.example.com/prosite/index.php?page=home),而是将其重定向到" http://www.example.com"。谢谢你的帮助。

RewriteEngine On

RewriteBase "/prosite/"

# redirect non-www addresses to www
# redirect condition: hostname does NOT contain 2 or more dots
RewriteCond "%{HTTP_HOST}" "!\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])\."
RewriteRule "^(.*)$" "http://www.%{HTTP_HOST}/prosite/$1" [R=301,L]

# redirect empty path to home page
RewriteRule "^$" "index.php?page=home" [NC,L]

# redirect page path to corresponding page
RewriteRule "^(home)/?$" "index.php?page=$1" [NC,L]

# redirect all other paths to index.php (without a "page" argument this will show the default page: 404 not found)
RewriteRule "!^index\.php$" "index.php" [NC,L]

1 个答案:

答案 0 :(得分:0)

显然这是一个浏览器缓存问题。我清空了缓存并且工作正常。