2013-03-30 44 views
0

我需要添加一些重写规则到网站。需要apache重写规则帮助

这里的想法=>

重写从

(http or https)://(www. or no www.)example.com/whatever 
(http or https)://www.example.com/whatever 

所有非子域交通(所以基本上,总是强迫WWW)

此外重写仅此1 sumbdomain =>

(http or https)://(www. or no www.)store.example.com/whatever 
(http or https)://www.example.com/whatever 

保留所有其他的s ubdomains完好无损。

到目前为止,我有这个=>

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example.com$ 
RewriteCond %{HTTP_HOST} ^store.example.com$ 
RewriteRule ^(.*)$ http%{ENV:askapache}://www.example.com/$1 [R=301,L] 

但它无法正常运行......

任何帮助将appriciated。

谢谢!

回答

1

启用mod_rewrite的,并通过httpd.conf的.htaccess,然后把这个代码在你.htaccessDOCUMENT_ROOT目录:

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

RewriteCond %{HTTP_HOST} ^(?:store\.)?example\.com$ [NC] 
RewriteCond %{HTTPS}s on(s)| 
RewriteRule^http%1://www.example.com%{REQUEST_URI} [R=301,L] 
+0

非常感谢您的投入,但我得到了“此网页有重定向循环”错误http://store.example.com/httpstore。://www.example.com .... – Andrej

+0

这是怎么回事,因为重定向的URI有主机www.example.com',这会导致这种情况失败:'RewriteCond %{HTTP_HOST} ^(store \。)?example \ .com $ [NC]'。你在.htaccess中还有其他的东西吗? – anubhava

+0

我做了一些小改动,你现在可以尝试编辑的代码吗? – anubhava