我的.htaccess文件中有这个:
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com$1 [R=301,L]
但每当我访问根目录下的文件,比如http://example.com/robots.txt,它就会重定向到http://www.example.comrobots.txt/。
我如何纠正这一点,使它将正确重定向到http://www.example.com/robots.txt?
以下是支持https和http的正确解决方案:
# Redirect to www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
乌利希期刊指南。:用于像.co这样的域名。英国,取代
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
with
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.[^.]+$
以下是支持https和http的正确解决方案:
# Redirect to www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
乌利希期刊指南。:用于像.co这样的域名。英国,取代
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
with
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.[^.]+$
这个配置为我在bitnami wordpress与SSL配置工作:
在/opt/bitnami/apps/wordpress/conf/httpd-app.conf文件中的“RewriteEngine On”下增加了以下内容
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]