Apache2在.htaccess中重写URL

Apache2在.htaccess中重写URL,.htaccess,url-rewriting,apache2,url-routing,.htaccess,Url Rewriting,Apache2,Url Routing,我想用www.example.org重写任何请求,然后 有没有简单的方法 我目前正在.htaccess中执行以下操作,但是->的情况不起作用 你知道我哪里会出错吗 也会因为这个重定向而影响任何搜索引擎的排名 这是URL重定向的最佳实践吗 我当前的.htaccess如下所示 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} example\.org RewriteCond %{HTTPS} !on Re

我想用www.example.org重写任何请求,然后

有没有简单的方法

我目前正在.htaccess中执行以下操作,但是->的情况不起作用

  • 你知道我哪里会出错吗
  • 也会因为这个重定向而影响任何搜索引擎的排名
  • 这是URL重定向的最佳实践吗
  • 我当前的.htaccess如下所示

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} example\.org
    RewriteCond %{HTTPS} !on
    RewriteRule (.*) https://example.com%{REQUEST_URI}
    </IfModule>
    
    
    重新启动发动机
    重写cond%{HTTP_HOST}example\.org
    重写cond%{HTTPS}!在…上
    重写规则(.*)https://example.com%{REQUEST_URI}
    

    谢谢

    请在.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
    是您的请求URI