我正在尝试编写一个htaccess重写规则,以便向lunre.com发送域http://或https://和www中的所有现有文件和目录,或者不发送。
因此,已经存在的lun.re/admin将转到lunre.com,而不存在的lun.re/new将留在lun.re,但会重定向到https://lun.re/new。
这是我到目前为止所知道的:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^lun\.re$ [OR]
RewriteCond %{HTTP_HOST} ^www\.lun\.re$
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://lunre.com/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]第5-8行已经从我的主机提供商那里了。
我也尝试过这个:
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /loader.php [L,R]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{HTTP_HOST} ^(www\.)?lun.re$
RewriteRule ^ http://lunre.com/ [L,R]但是我得到了一个太多重定向的错误。
我到底要做的是,如果它确实存在,并且域是lun.re,则转到https://lunre.com/file-or-dir (长url处的相同文件路径),否则,如果它不存在,则留在当前域并转到https://currentdomain/loader.php
发布于 2018-03-05 23:12:40
您可以使用以下命令:
RewriteEngine on
# http to https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]
#redirect all existing files/directories to http://lunre.com
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{HTTP_HOST} ^(www\.)?lun.re$
RewriteRule ^ http://lunre.com/ [L,R]您不需要RewriteRule来将不存在的请求重定向回您的主域,因为规则只重定向现有的文件/文件夹。
https://stackoverflow.com/questions/49112395
复制相似问题