Forum Moderators: phranque
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^ab\.cd\.ef\.gh$
RewriteCond %{REQUEST_URI} !^index2\.html
RewriteRule .* index2.html
RewriteRule ^images/(.+)?$ images/$1 [L]
Begin the link to images, css files and javascript files with a leading slash and state the full path to the folder.
It is the browser that works out the location of these objects. This location is a URL.
From this page: "example.com/folder/thispage.html" a link to "images/image.jpg" points to "example.com/folder/images/image.jpg".
If your image is really at "example.com/images/image.jpg" then you need the links on your pages to instead point to "/images/image.jpg" with a leading slash.
No you do not need to rewrite the images!
The html within the pages themselves should give the full address of the image. If the image lives at
www.example.com/images/picture23.jpg
then the html would say <img src = "/images/picture23.jpg"> with leading slash. With this format, it does not matter where the html file lives.
Now, if index.html and index2.html live in the same directory, and are identical in every way, but only one of them shows the images-- then you've got a head-scratcher.
Incidentally, since you're rewriting rather than redirecting, and the two files are identical, how do you know which one you're looking at? That is, how can you be sure the rewrite is happening? Do they at least have different titles?
Do not use the ../ notation here. Start the link with a leading slash.
Now you have explained some more, it looks like you should have previously linked to /images/filename.ext and set up a RewriteRule to rewrite external requests for example.com/images/<something> to the internal filepath /writest/images/<something>
URLs are used "out there" on the web. Filepaths are used "here" inside the server. They are not at all the same thing. They are merely "related" by the action of a server, and the way that server is configured.
Begin the link to images, css files and javascript files with a leading slash and state the full path to the folder.
www/htdocs/writest/] strip per-dir prefix: /home/users/www/htdocs/writest/index2.html -> index2.html
www/htdocs/writest/] applying pattern '.*' to uri 'index2.html'
www/htdocs/writest/] RewriteCond: input='aa.bb.cc.dd' pattern='^aa\.bb\.cc\.dd$' => matched
www/htdocs/writest/] RewriteCond: input='/writest/index2.html' pattern='!^index2\.html' => matched
<html>
<head>
<title>index page (1)</title>
<body>
<p>
This is index page 1.
</p>
<center>
<img src="images/test.jpg">
</center>
</body>
</html>
<html>
<head>
<title>index page (2)</title>
<body>
<p>
This is index page 2.
</p>
<center>
<img src="images/test.jpg">
</center>
</body>
</html>
<Directory /home/users/www/htdocs/writest>
AllowOverride All
</Directory>
http://www.site.com/writest/index.html
http://www.site.com/writest/index2.html
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^aa\.bb\.cc\.dd$
RewriteCond %{REQUEST_URI} !^index2\.html
RewriteRule .* index2.html
shouldn't matter if I use
src="images/test.jpg"
src="/home/www/htdocs/writest/images/test.jpg"
src="http://www.site.com/writest/images/test.jpg"
RewriteRule .* index2.html
You shouldn't include the index filename in the href part of the links on your page. You should link to the canonical URL and this should end with a trailing slash after the parent folder name (or just a slash for root).
The DirectoryIndex directive sets the filename that is served for such a request. It's a special type of rewrite, and much more efficient.
It's a good idea to redirect URL requests that include a reference to an index filename to strip that filename from the request.
In your original post I missed the Rule with .* in it. One tip for laying out mod_rewrite code for clarity: include a blank line after every RewriteRule.