如何结合不同的apache重定向?

时间:2017-02-06 11:52:21

标签: apache .htaccess redirect

我正在尝试组合不同的apache重定向。我认为只要摆脱任何L ast旗就可以做到这一点,但事实并非如此(见How to combine Apache redirects?)。它使以下两个登陆页面重定向

example.org - > www.example.org - > www.example.org/products/

但我宁愿拥有

example.org - > www.example.org/products/

以避免延误。

以下是.htaccess文件:

# FORCE WWW
RewriteCond %{HTTP_HOST} !^www\.example\.org$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$ http://www.example.org/$1 [R=301]

# REDIRECT FROM ROOT TO PRODUCTS(.PHP)
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /products/ [R]
RewriteRule ^products/$ /products/products.php

# ADD TRAILING SLASH
RewriteRule ^(([^/]+/)*[^./]+)$ http://www.example.org/$1/ [R=301]

# INTERNAL REWRITE OF "products/myname/myversion/" to "products/products.php?name=myname&version=myversion"
RewriteRule ^products/([a-z0-9-]+)/([0-9-]+)/$ products/products.php?name=$1&version=$2 [NC]
RewriteRule ^products/([a-z0-9-]+)/$ products/products.php?name=$1 [NC]

1 个答案:

答案 0 :(得分:0)

尝试这样,目前我没试过,

#FORCE WWW with products 

RewriteCond %{HTTP_HOST} ^example.org [OR]
RewriteCond %{REQUEST_URI} !^products
RewriteRule ^(.*)$ http://www.example.org/products/$1 [R=301]

删除这些行

RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^$ /products/ [R]