logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Rewrite or Redirect permanent?
Author
Krischu



Joined: 23 Oct 2009
Posts: 25

PostPosted: Tue 25 Jul '23 16:45    Post subject: Rewrite or Redirect permanent? Reply with quote

In my VirtualHost *:80 section I have a

Code:
Redirect permanent / https://www.myhost.tld/


Later in the secure host section I have a

Code:
Redirect permanent /master https://myhost.ddnss.tld:8083/fs/web/Master11/


This works fine. But when I want to pass something like

Code:
/master/Master22
, how can I achieve this?
That the result is e.g.
Code:
https://myhost.ddnss.tld:8083/fs/web/Master22/
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 348
Location: UK

PostPosted: Tue 25 Jul '23 22:56    Post subject: Reply with quote

I would go for rewrite everytime.

Your current VirtualHost *:80 section only redirects requests for the site root, whereas the following alternative redirects any non-secure request to its secure equivalent.

Code:
# Define default virtual host
#
<VirtualHost *:80>
    # Inherit any global mod_rewrite rules
    #
    RewriteEngine On
    RewriteOptions InheritBefore

    # Check for a non-secure HTTP request and if found redirect to HTTPS.
    #
    RewriteCond %{HTTPS} off
    RewriteRule ^/(.*)$ https://www.myhost.tld/$1 [L,NE,R]

</VirtualHost>

Similarly, for your default secure section, define a list of redirects as required, e.g.

Code:
# Define secure site virtual host
#
<VirtualHost *:443>
    # Inherit any global mod_rewrite rules
    #
    RewriteEngine On
    RewriteOptions InheritBefore

    # Enable SSL for this virtual host.
    #
    SSLEngine on

    # Define rewrite redirect rules.
    #
    RewriteRule ^/master$ https://myhost.ddnss.tld:8083/fs/web/Master11 [L,NE,R]

    RewriteRule ^/master/Master22$ https://%https://myhost.ddnss.tld:8083/fs/web/Master22 [L,NE,R]

    # Other virtual host directives ...

</VirtualHost>

The default redirect with rewrite rules is temporary (302), not permanent (301). If you want permanent use flag R=301 instead of R.

My preference is to stick with temporary redirects, since permanent ones may be cached by client browsers, and if you subsequently alter your site redirects, they won't see the change.
Back to top
Krischu



Joined: 23 Oct 2009
Posts: 25

PostPosted: Wed 26 Jul '23 9:36    Post subject: Reply with quote

Thanks for the detailed answer. I will follow your advice, for one regarding using temporary Redirects instead. And going for Rewrite.
Back to top


Reply to topic   Topic: Rewrite or Redirect permanent? View previous topic :: View next topic
Post new topic   Forum Index -> Apache