.htaccess重定向循环与RewriteCond

时间:2018-09-13 05:09:31

标签: .htaccess redirect

我正在尝试重定向特定页面

  

http://www.my.website/admin

  

https://my.website/admin/

使用此代码:

Redirect 301 /admin/ https://my.website/admin/

但是它一直循环播放,我找不到原因,因为我指定了不存在“ www”的条件。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.tci\.rocks$ [NC]
RewriteRule ^admin/?$ https://my.website/admin/ [L,R=301]
</IfModule>

# BEGIN WithoutWWW
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
# END WithoutWWW

# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>
# END YOURLS

<IfModule mod_autoindex.c>
   Options -Indexes
</IfModule>

如何使此.htaccess停止循环?

1 个答案:

答案 0 :(得分:1)

改为使用:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.my\.website$ [NC]
RewriteRule ^admin/?$ https://my.website/admin/ [L,R=301]
</IfModule>