MyBB Community Forums

Full Version: [how to] apache mod_rewrite
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
this isn't a myBB question because i have google seo already installed to do this for my board.

this is a general question about another domain i have.

if i want to rewrite:

http: // domain . com (missing WWW)

...and...

http: // www . domain . com / index . html (trailing index.html)

...to:

http: // www . domain . com /

what exactly would i put into a .htaccess file? (sorry, as i'm sure people get very sick of this question)
Maybe like this

RewriteRule ^index\.php$ http://www.domain.com/ [L,QSA,R=301]
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,QSA,R=301]
(2010-12-04, 11:07 PM)frostschutz Wrote: [ -> ]Maybe like this

RewriteRule ^index\.php$ http://www.domain.com/ [L,QSA,R=301]
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,QSA,R=301]
RewriteRule ^index\.php$ http://www.domain.com/ [L,QSA,R=301]
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,QSA,R=301]

here is something a lil bit similar:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?somesite.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.somesite.com/nasty.gi

Source Copied From [url=http://www.workingwith.me.uk/articles/scripting/mod_rewrite Wrote:here[/url]:]
Conditional Statements and mod_rewrite

But what happens when you start getting people hotlinking to your images (or other files)? Hot linking is the act of including an image, media file, etc from someone else’s server in one of your own pages as if it were your own. Obviously, as a webmaster, there are plenty of times when you don’t want people doing that. You’ll almost certainly have seen examples where someone has linked to one image on a website, only for a completely different, “nasty” one to be shown instead. So, how is this done?

It’s pretty simple really. All it takes are a couple of RewriteCond statements in your .htaccess file.

RewriteCond statements are as they sound - conditional statements for RewriteRules. The basic format for a RewriteCond is RewriteCond test_string cond_pattern. For our purpose, we will set the test_string to be the HTTP_REFERER. If the test string is neither empty nor our own server, then we will serve an alternative (low bandwidth) image, which tells the person who is hotlinking off for stealing our bandwidth.

Here’s how we do that:
(ABOVE)
(2010-12-04, 11:07 PM)frostschutz Wrote: [ -> ]Maybe like this

RewriteRule ^index\.php$ http://www.domain.com/ [L,QSA,R=301]
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,QSA,R=301]

frostschutz,

i tried that code. however, i changed the ".php" to ".html", but it gave me a warning saying too many redirect loops set up.
i got it...

Quote:Options +FollowSymLinks

RewriteEngine on

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]