2016-03-21 38 views
1

我想重定向站點ip到我的站點https以及我想重定向非www網址到www網址。我已經寫了這兩條規則,但它們是相互衝突的。這裏是我的凱德:在htaccess中衝突多個重定向規則

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

#Redirect ip to site 
RewriteCond %{HTTP_HOST} ^xx\.xx\.xxx\.xxx$ 
RewriteRule ^(.*)$ https://www.domain.pk/$1 [L,R=301] 

#Redirect non-www to www 
RewriteCond %{HTTPS_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.domain.pk/$1 [R=301,L] 

</IfModule> 

# END WordPress 
+0

http://stackoverflow.com/questions/17453412/redirect-to-http-non-www-to-https-www-htaccess – Damien

+0

@Damien,個別情況下工作正常,但兩者共同,不工作 –

+0

你的問題到底是什麼?你得到一個重定向循環或什麼? – starkeen

回答

0

你試過這個配置嗎?

RewriteEngine On 
RewriteBase/

RewriteCond %{HTTPS} off [OR] 
RewriteCond %{HTTP_HOST} ^xx\.xx\.xxx\.xxx$ [OR] 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.domain.pk/$1 [L,R=301] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L]