question_ redirecting unsuccessful requests with htaccess

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

question_ redirecting unsuccessful requests with htaccess

Post by pedrotuga »

I am in the process of making major changes in a website. A lot of the content will be taken away, but i stll want to get all the visitors from google.

I have a forum in http://mysite.com/forum
But now I am taking it away and I want to redirect all those users to:
http://mysite.com/news.htm

would something like this be ok?

^/forum/(.*)(.htm|/|.php) /news.htm #.htm .php and / are the only possibilities for my forum's urls.

Also, don't know which chars to escape in htaccess regex...

Like... is this necessary?...

^/forum/(.*)(\.htm|\/|\.php) /news.htm

What about this?

^/forum/(.*) /news.htm

Is it dangerous in any way? why? how?

thanks in advance
samb0057
Forum Commoner
Posts: 27
Joined: Wed Mar 26, 2008 9:51 am

Re: question_ redirecting unsuccessful requests with htaccess

Post by samb0057 »

Just make an index file in the forum/ directory with the following code:

<?php
header('Location: http://www.mysite.com/whatever/');
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: question_ redirecting unsuccessful requests with htaccess

Post by pickle »

samb0057 wrote:Just make an index file in the forum/ directory with the following code:

<?php
header('Location: http://www.mysite.com/whatever/');
Um... no that won't work unless someone requests either no file or index.php. If someone requests blah.php, they'll still get a 404 error....

...Which is exactly what you should be looking into ~pedrotuga. Do a Google search for something along the lines of 404 .htaccess redirect
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply