Forum Moderators: phranque
I am using this in htaccess file to add banner to all html pages:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /public_html/
RewriteCond %{REQUEST_FILENAME}!header.php
RewriteCond %{REQUEST_URI} ^(.*)/$ [OR]
RewriteRule ^(.*)\.html$ [mydomain\.com...] [R,L]
It works, but the web browsers's shows this url as:
[mydomain.com...]
, and all http links in index.html like [mydomain.com...]
instaed of
[mydomain.com...]
Can anyone help me?
Regards
1. Use SSI and at the top of pages EG
<!--#include virtual="/path/to/your/banner.gif" -->
2. Use php auto_prepend_file EG
Added: For php V4 below - you will have to define the version you are running for changes to take effect.
<IfModule mod_php4.c>
php_value auto_prepend_file "/path/to/your/banner.gif"
</IfModule>
If you had to you could add a handler type to handle the html files as php (It will cost you some processing overhead, so be careful.)
Mod_Rewrite is *not* designed to do what you are attempting, and therefore creates a cumbersome, messy solution. I highly recommend using one of these two instead, which are designed for exactly what you are doing.
If you need help implementing them, let us know.
Hope this helps.
Justin
RewriteEngine on
RewriteCond %{QUERY_STRING} !.
RewriteRule ([^.]+)\.html$ /header.php?file=%{REQUEST_FILENAME} [L]
This should create an internal redirect if there is no query string, and silently serve the information from the new location to the requested location. Not ideal, but might work.
Justin
You will need to add a query string to the requested URL to break the loop.
$location = $_GET['file']."?anything";
Should have no effect on the file, but is the only way (I can think of) to tell if the URL has been processed by your script or not.
Justin