htaccess redirect only if domain matches

后端 未结 2 1918
我在风中等你
我在风中等你 2021-02-08 11:35

I have a problem where I need to redirect my domain before it hits php. By the time it hits the ability to execute a header, it is too late.

How can I do



        
2条回答
  •  生来不讨喜
    2021-02-08 12:17

    As of Apache 2.4 you can use an Directive to achieve what you suggested:

    
      RedirectMatch (.*) http://www.example2.com$1
    
    

    For a case-insensitive version that matches with or without the www you can do:

    
      RedirectMatch (.*) http://www.example2.com$1
    
    

    Sources:

    • Apache Blog: New in httpd 2.4: If, ElseIf, and Else
    • Apache 2.4 Documentation: If Directive

提交回复
热议问题