php.htaccessmod-rewritelitespeedopenlitespeed

How redirect URL to to file In Cyberpanel and OpenLitespeed


How can I redirect URL to to file In Cyberpanel and OpenLitespeed?

dl.mydomain.com/vid to mydomain.com/myfile.zip

I used this code inside /vide directory, but is not working

RewriteEngine on
RewriteCond %{HTTP_HOST} ^dl\.mydomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.dl\.mydomain\.com$
RewriteRule ^vid\/?$ "https\:\/\/mydomain\.org\/myfile\.zip" [R=301,L]

Solution

  • dl.example.com/vid to example.com/myfile.zip

    Aside: Note that if /vid is a physical directory then you should be requesting /vid/ (with a trailing slash), otherwise mod_dir will issue a 301 redirect to first append the trailing slash.

    The RewriteRule pattern matches the URL-path relative to the directory that contains the .htaccess file. So, if "this code inside /vide directory" (although I assume you mean /vid?) then this should be omitted from the URL-path you are trying to match.

    For example:

    # /vid/.htaccess
    
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^(www\.)?dl\.example\.com [NC]
    RewriteRule ^$ https://example.com/myfile.zip [R=301,L]
    

    Note that you used .com in your example, but .org in your rule. I'm assuming this should be .com.

    There is no need for all the backslash-escapes in the substitution string (2nd argument to the RewriteRule directive) - this is an "ordinary" string, not a regex (but even if it was, colons and slashes wouldn't need to be escaped). (This is very cPanel-esque).