Forum Moderators: phranque

Message Too Old, No Replies

Can someone help me with my .htacess - I think it's probably crud!

         

NeilF

9:19 pm on Aug 15, 2006 (gmt 0)

10+ Year Member



Up until now the only two rules I've really been concerned about are:-
a) Enforcing www on my domain (seems to prevent cookies problems on my forum).
b) Stopping other sites leeching my images.

However, I now want to introduce a subdomain for my forum (eg: forum.mydomain.com) however, this means problems with both the above two rules:-
a) I end up with www.forum.mydomain.com
b) No images are shown for for forum

I'm wondering if someone can look at my mess of an HTACCESS and tell me how to change it to only allow www.mydomain.com and forum.mydomain.com, and only to allow images to by pulled from those.


ErrorDocument 404 /filenotfound.html
AddType text/x-server-parsed-html .html
IndexOptions -FancyIndexing
RewriteEngine On
RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www. ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)¦.*)$ [OR,NC]
RewriteCond %{HTTP_HOST}/www. ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))$ [NC]
RewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]
RewriteCond %{HTTP_REFERER}!^http://www.mydomain.com [NC]
RewriteRule [^/]+.(gif¦jpg)$ - [F]

I was trying something like this, but it's invalid and I have no idea why :(

ErrorDocument 404 /filenotfound.html
AddType text/x-server-parsed-html .html
IndexOptions -FancyIndexing
RewriteEngine On
RewriteCond %{HTTP_HOST}!^(www¦forum).mydomain.com
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{HTTP_REFERER}!^http://(www¦forum).mydomain.com [NC]
RewriteRule [^/]+.(gif¦jpg)$ - [F]

jdMorgan

9:42 pm on Aug 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's not much wrong with that code, but if you copied and pasted it from here and didn't read the warnings, then you may have formatting-related problems -- check your server error log. The following code with a few minor corrections should work:

ErrorDocument 404 /filenotfound.html
AddType text/x-server-parsed-html .html
IndexOptions -FancyIndexing
RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^(www¦forum)\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_REFERER} !^http://(www¦forum)\.example\.com
RewriteRule \.(gif¦jpg)$ - [F]

This forums deletes spaces preceding "!" which can cause errors, and it also turns the pipe character into a broken pipe "¦" character, which changes the meaning of a regular expression containing it. You will need to change the broken pipes to solid pipes before use.

Jim