Redirecting from file to another?

Discussion about the creation of websites in general, HTML, PHP, Java.

Redirecting from file to another?

Postby JaMaHa on Wed Oct 04, 2006 7:05 pm

Yay, more problems. Anyway...

I have a script that list files and links to download them from. Most of the links link to a .mus file but there are a few .htm files. I figured that making a redirect would be the easiest way but how do you actually redirect? I need to make it so that whenever someone visits the non-existing blahblahblahfilenamehere.mus it should redirect it automatically to blahblahblahfilenamehere.htm.

Any ideas how to do that?
Image
JaMaHa
Regular
Regular
 
Posts: 93
Joined: Mon May 08, 2006 3:54 pm
Location: Finland

Postby Samppa on Wed Oct 04, 2006 7:12 pm

Depending on your website, how about just a 404 page? Or, if possible, just a 404 page for the directory.


Example:
http://www.thesitewizard.com/archive/custom404.shtml
(\__/)
(='.'=) This is RomMaster's Bunny. Copy and paste bunny into your
(" )_(" ) signature to help him gain world domination.
Samppa
Phoenix Veteran
Phoenix Veteran
 
Posts: 744
Joined: Thu Feb 02, 2006 10:00 am
Location: Finland

Postby JaMaHa on Wed Oct 04, 2006 8:16 pm

Okay, maybe using a .htm file in the example was a bad idea. If the file the link links to is .filetype1 but there's no such a thing. But instead there's a file with a file extension .filetype2 and I want it to redirect it to that one?
Image
JaMaHa
Regular
Regular
 
Posts: 93
Joined: Mon May 08, 2006 3:54 pm
Location: Finland

Postby kovach on Wed Oct 04, 2006 9:37 pm

mod_rewrite

RewriteEngine ON
RewriteRule ([^.]+)\.ccc /dir/newfile$1.html [L]

and 4 non-existing you can make script which check first and then send header.
kovach
Contributer
Contributer
 
Posts: 49
Joined: Wed Jun 14, 2006 10:55 pm
Location: Serbia

Postby trick on Sun Oct 08, 2006 8:45 pm

mod_rewrite rocks. BTW, if you actually want to redirect it, this is what you want:

RewriteEngine ON
RewriteRule ([^.]+)\.ccc /dir/newfile$1.html [L,R]
'The military don't start wars. Politicians start wars' - William Westmoreland
Image
trick
Contributer
Contributer
 
Posts: 74
Joined: Mon Aug 07, 2006 6:07 am

Postby JaMaHa on Mon Oct 09, 2006 10:12 am

Yeah, thanks for the help. mod_rewrite worked great.
Image
JaMaHa
Regular
Regular
 
Posts: 93
Joined: Mon May 08, 2006 3:54 pm
Location: Finland


Return to General Webmastering

Who is online

Users browsing this forum: No registered users and 1 guest

cron