Mysteltainn
Mysteltainn

Reputation: 421

.htaccess rewrite full domain name

Are there anyway to make a user get to download thefile by let them type:download.mywebsite.com/thefile in the browser address while the "download.mywebsite.com/thefile" does not exist but the "www.mywebsite.com/thefile" does.

I've got nearly zero knowledge with .htaccess and mod_rewrite engine. I hope my question is clear.

Upvotes: 1

Views: 673

Answers (2)

JoeCortopassi
JoeCortopassi

Reputation: 5093

RewriteEngine On

RewriteRule ^/download/(.*)$ http://download.mywebsite.com/$1 [R=301,L]

You need to set up your web server to listen for sub-domains as well

Upvotes: 1

nyxthulhu
nyxthulhu

Reputation: 9752

IF you own mywebsite.com then yes you could, you would have to place a ServerAlias in your root httpd.conf directive then use mod_rewrite to re-write all requests for download.mywebsite.com/thefile to www.mywebsite.com/thefile but the mod_rewrite would not know if a file exists or not in advance.

Another way to do it would be implement a custom error document for a 404 handler which redirects a user to a suggested URL.

Upvotes: 2

Related Questions