.htaccess中的Apache2重写URL

| 我想用www.example.org,https://www.example.org和http://example.org将任何请求重写为https://example.org 有一个简单的方法吗? 我目前正在.htaccess中执行以下操作,但是https://www.example.org-> https://example.org的情况不起作用。 有什么想法我可能会出错吗? 由于这种重定向,它还会影响任何搜索引擎排名。 这是URL重定向中的最佳实践吗? 我当前的.htaccess看起来像这样。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} example\\.org
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://example.com%{REQUEST_URI}
</IfModule>
谢谢
已邀请:
在您的.htaccess文件中尝试以下操作:
Options +FollowSymLinks
RewriteEngine on

# redirect for http
RewriteCond %{HTTP_HOST} ^(www\\.)?example\\.org$ [NC]  
RewriteCond %{SERVER_PORT} =80
RewriteRule ^/?(.*)$ https://example.org/$1 [R=301,QSA,L,NE]

# redirect for https
RewriteCond %{HTTP_HOST} ^www\\.example\\.org$ [NC]  
RewriteCond %{SERVER_PORT} =443
RewriteRule ^/?(.*)$ https://example.org/$1 [R=301,QSA,L,NE]
R=301
将重定向为https状态301
L
将成为最后的规则
NE
表示不转义查询字符串
QSA
将附加您现有的查询参数
$1
是您的REQUEST_URI

要回复问题请先登录注册