Hi, my server is indicated by two domains dom1 and dom2.

I want to make it so that when requesting for dom1 - everything worked properly, and when requesting for dom2 there was a redirect to dom1 / hi.php.

My config:

<VirtualHost *:80> DocumentRoot "D:/htdocs" ServerName dom1 </VirtualHost> <VirtualHost *:80> ServerName dom2 RewriteEngine On RewriteRule .* http://dom1/hi.php [R] </VirtualHost> 

Now redirection only occurs if there are characters after dom2 / .... If you request http: // dom2 , then a request error will be issued.

How to do, even if there are no characters?

    1 answer 1

    I think that if in your version replace the next line

     RewriteRule .* http://dom1/hi.php [R] 

    on

     RewriteRule ^(.*)$ http://dom1/hi.php [R] 

    Although in essence your option should have worked.

    Only here the data after the slash will be lost. If you want to transfer it to another url then:

     RewriteRule ^(.*)$ http://dom1/hi.php$1 [R] 

    These parentheses are like variable values. You can get them through the operator $n , where the letter n is the number indicating which parenthesis (the value falling under this expression) on the account to take.

    A URL like this dom2/aaa/bbb/ccc

     RewriteRule ^(.*)/(.*)/(.*)$ http://dom1/hi.php$1 [R] 

    after RewriteRule ... redirected to http://dom1/hi.php/aaa . if you need to transfer bbb then we take the second parentheses, that is, $2 :

     RewriteRule ^(.*)/(.*)/(.*)$ http://dom1/hi.php$2 [R] 

    And by analogy.

    My suggestions:

    You can use the RedirectMatch directive to force Apache to send the user somewhere else:

    Option 1:

     <VirtualHost *:80> ServerName dom2 RewriteEngine On RedirectMatch 301 ^(.*)$ http://dom1/hi.php$1 </VirtualHost> 

    Option 2:

     <VirtualHost *:80> ServerName dom2 ServerAlias www.dom2 RedirectPermanent / http://dom1/hi.php ServerAdmin admin@redirectedurl.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 

    See the following:

    RedirectMatch Directive

    HTTP status codes 3xx

    • <VirtualHost *: 80> ServerName domen2 Redirect / " domen1 / daily.php " </ VirtualHost> It worked, but yours is also correct, it turned out - the cache browser issued)) - yavafree
    • How does the starting line help? - Alex78191