Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

simple mod_rewrite question

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

New User

joined:Aug 6, 2003
votes: 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 ..

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0


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]


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

New User

joined:Aug 6, 2003
votes: 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]


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

All I got is 500 server error.

Any Ideas?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 15, 2003
votes: 5

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?