簡體   English   中英

htaccess中的多個重定向規則沖突

[英]Conflicting multiple redirect rules in htaccess

我想將網站IP重定向到我的網站https以及我想將非www網址重定向到www網址。 我寫了這兩條規則,但它們是沖突的。 這是我的嘲笑:

# 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

你試過這個配置嗎?

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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM