PDA

View Full Version : Apache mod rewrite help needed


yanni
19th April 2010, 01:07 AM
I have a video search engine which pulls content form various external video sources and creates pages dynamically.

Is there a way to prevent certain keywords from being searched, in the .htacces file with mod rewrite and redirect requests to index page?
I tried a 301 redirect old file, but didn't work.

Any help or guidance appreciated.

TIA :)

squirrel
19th April 2010, 01:43 AM
Your script file that your search form is sending variables to using GET/POST, it could go through a wordlist. If the keyword is in the word list, the user gets redirected to a specific page, if not, the script fetches search results.

Your wordlist could be a separate file so you can update it whenever you want and just upload it on your server.

Is that what you're looking to do ?

yanni
19th April 2010, 02:23 AM
Squirrel, thanks for the reply.

Yes there is a bad words list and I added the keywords I need excluded there, but it doesn't seem to work.

Since I am php-challenged does the following snipplet of code show the major bad words list on or off? I assume it's on. None of the banned words work on the site though. It pulls video unless there isn't any at the source.

----------------------------------------------

//start new
$i = 0;
while($i<count($major_badwords)) {
$banwords .= "-".$major_badwords[$i]."+";
$i++;

}

/// end new

----------------------------------------------------------------

That's why I wondered if this could work with htacces

Thanks again for your time.

yanni
19th April 2010, 02:42 AM
OK, I figured it out on the videos part. Now I've got do figure it out to exclude the words from the rss feed [news].

jose
19th April 2010, 03:37 AM
Yes, you can do it with htacces.

Check this example, which blocks based on keywords like Viagra:

http://www.askapache.com/htaccess/real-world-htaccess-files.html#menu0-el10

One of my favorite htacces ever.

yanni
19th April 2010, 09:41 AM
Thanks for the link Jose. Much appreciated.

Lots of learning for me to do, which is always welcome ;]

squirrel
19th April 2010, 03:19 PM
Good luck Yanni.

If you still want to do it using php, there's plenty of "bad words filter" templates online. You can find one easily then use php.net to understand each functions used in the template.

mdw
20th April 2010, 12:26 AM
Yes, you can do it with htacces.

Check this example, which blocks based on keywords like Viagra:

http://www.askapache.com/htaccess/real-world-htaccess-files.html#menu0-el10

One of my favorite htacces ever.

UGGGHHHH!!!!!

Don't ever do this folks. You put this into an .htaccess file and it gets read and parsed on every request matching that directory! If you put this beast into the root dir you're doing this file IO on every request. At least for apache server.

If you really think you want to handle this filtering task at the server config level instead of in the application logic then it belongs in the server config file. That way it's read once, when the process starts up, and that's it.

This is akin to making your restaurant waiter put on very heavy shoes. In the best case he still may serve you your meal with little or no degradation of performance, but in the worst case the service will deteriorate noticeably.

jose
20th April 2010, 01:47 AM
I have a site with a very heavy htacess and didn't notice any visible degradation of speed, but I might be wrong. Anyway askapache are the experts, not me.

mdw
20th April 2010, 02:36 AM
I have a site with a very heavy htacess and didn't notice any visible degradation of speed, but I might be wrong. Anyway askapache are the experts, not me.

Well for a busy server it's a lot of extra overhead. But if it gets the kind of traffic that my Chinese domains get it's a moot point.

I'm considering a process where, on every HTTP request to a Chinese domain of mine, a carrier pigeon delivers a notification to me, I boot up a windows server [install some patches], and fire up IIS to serve that request and then shut it all down afterward. Hopefully I don't go thru all that every year.