Redirect from subdomain to main domain for error page

New to mod_rewrite? This is a good place to start.

Redirect from subdomain to main domain for error page

Postby gary » Thu Jul 02, 2009 5:02 am

Links are uniques in this format, only sub.domain.com/downloads/ is the same each time
http://sub.domain.com/downloads/1/jfqs3 ... lename.zip

How to make the parts right before the filename to be included in the redirection for a 404 error?

Example
http://sub.domain.com/downloads/1/jfqs3 ... lename.zip
to
http://domain.com/a92i3dk59anb


Thanks!
gary
 
Posts: 7
Joined: Sun May 10, 2009 3:48 pm

Postby richardk » Fri Jul 03, 2009 9:10 am

It should only work if the file does not exist?
Are they always .zip files?
Does download or 1 change?

Try the following in sub.example.com/.htaccess
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^downloads/(.*/)?([^/]+)/[^/]+$ http://example.com/$2 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby gary » Fri Jul 03, 2009 8:34 pm

Should only work if file does not exist
Not always .zip files, ext is dynamic
Download stays the same, the 1 changes

Tried the code you posted, worked perfectly, thanks!
gary
 
Posts: 7
Joined: Sun May 10, 2009 3:48 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 107 guests

cron