Forum Moderators: phranque

Message Too Old, No Replies

simple mod_rewrite question

         

affter333

11:16 pm on Aug 22, 2003 (gmt 0)



Below is my htaccess

======================================
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://www.MY-DOMAIN.com/(.*)$ [NC]
RewriteCond %{REQUEST_FILENAME}!^(.*)Start-UP.htm(.*)$ [NC]
RewriteRule \.(htm¦html¦gif¦jpg¦doc)$ [MY-DOMAIN.com...]
========================================

I have two Q for you :)

1. I have files that have no any file extension
[data1] [data2] etc
how do I include these in rewriteRule

2. if I want to apply all file type in RewriteRule
How do I do it?
This list is too long. (htm¦html¦gif¦jpg¦doc png txt)

Thanks for your kind help ..

jdMorgan

11:43 pm on Aug 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



affter333,

Welcome to WebmasterWorld [webmasterworld.com]!

To redirect all files, just omit the list and use ".*"

Having done that, you can simplify this by removing one RewriteCond as well, by including the REQUEST_FILENAME pattern in the RewriteRule itself.


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www\.MY-DOMAIN\.com [NC]
RewriteRule !^Start-UP\.htm$ http://www.MY-DOMAIN.com/Start-UP.htm [NC,R=301,L]

Note also that "^.*" and ".*$" are redundant, and can be omitted unless the pattern (.*) is needed for a backreference.

Ref: Introduction to mod_rewrite [webmasterworld.com]

Jim

affter333

10:33 pm on Aug 23, 2003 (gmt 0)



Hi, thanks, but I still can't figure out
how to specify files that have no extension

let's say I want to restrict jpg,gif and no-ext files.

I used:

RewriteRule \.(jpg¦¦gif)$ [nolinking.com...] [R,L]

OR

RewriteRule \.(jpg¦gif¦)$ [nolinking.com...] [R,L]

All I got is 500 server error.

Any Ideas?

claus

10:39 pm on Aug 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to restrict files without an extension you have to match the file names. You can not match an extension that is not there.

If all these files are in one separate directory and nothing else is in this directory, you can just match the directory name. If they are spread all over the place it is more difficult.

Another way to do it would be to rename these files so that all included some special set of charactes, say "xz~zx" or something, then you could include this pattern in the rewrite rules. If the files have all kinds of funny names it is more difficult.

So the question is, what do these files have in common apart from no extension?

/claus