Forum Moderators: phranque
That part is working, but the local images are not showing up. Only images linked from other sites are being displayed.
Here's the .htaccess I have so far.
RewriteEngine On
Options FollowSymLinks
# See if an image is requested and deliver as-is
RewriteCond %{REQUEST_URI} ^\.(gif¦jpg¦png)
RewriteRule ^.\.(gif¦jpg¦png)$ - [NC,L]
# See if the request file is a folder. If not, rewrite URL with IBA
RewriteCond %{REQUEST_FILENAME}!-d [OR]
RewriteCond %{REQUEST_FILENAME} =*.php* [OR]
RewriteCond %{REQUEST_FILENAME} =*.htm*
RewriteRule ^(.*) /\?IBA=$1 [QSA,L]
Here's a link to the test pages:
http://www.example.com/ Main page
http://www.example.com/jeff non-existing user
http://www.example.com/test existing user
Any ideas on how to rewrite that and get the local images to work are welcome.
Thanks!
Jim Hutchinson
[edited by: Brett_Tabke at 5:00 am (utc) on Dec. 22, 2004]
[edit reason] examplized. [/edit]
Welcome to WebmasterWorld!
Your image URI check will fail because you start-anchored it. The RewriteCond is redundant and not needed. The correct code would be:
# If an image is requested, bypass all subsequent rules
RewriteRule \.(gif¦jpg¦png)$ - [NC,L]
The directory rewrite code does not appear to do what you say you want to do, and so does not seem correct, but I can't tell from your description what you intended to accomplish with it. The tests for .php, .htm, and .html extensions are confusingly unexplained.
Note that posting on this forum changes pipe characters to broken pipe "¦" characters. You will have to edit them, and change them back to solid pipes if you cut and paste from this forum.
Jim
What I'm trying to do is move away from creating the folder since having several thousand of them in a single folder causes maintenance problems and can cause Apache to stop listing the files if there are too many.
The test for .htm* and .php files are there so we can continue processing those files. Ideally, if the file exists, we show it. Otherwise redirect the browser to the main page.
So what we have is: test for a folder, then the file. Images are to be left alone and delivered as-is. The code has been appearing to work except the images.
I hope that helps clear it up. If there a better way to write it, I'm open to learning a better way.
Thanks
Jim
Your code for the images works only if I don't call a specific file. Example, if I access /test/index.php the image doesn't show up. But if I go to /test/ it does. Must have something to do with the directory code? I tried many other ways of writing it but most of the variants resulted in a Page Not Found error, which is exactly what I'm trying to avoid.
# See if the request file is a folder. If not, rewrite URL with IBA
RewriteCond %{REQUEST_FILENAME}!-d [OR]
RewriteCond %{REQUEST_FILENAME} \.(php*¦htm*)
RewriteRule ^(.*) /\?IBA=$1 [QSA,L]
Any ideas?
Jim
# If request is not for html, htm, php, txt, gif, jpeg, jpg, or png files
RewriteCond %{REQUEST_URI} !\.(html?¦php¦txt¦gif¦jpe?g¦png)$
# and if the current query string does not include an aff id
RewriteCond %{QUERY_STRING} !IBA=
# and the requested resource does not exist as a directory
RewriteCond %{REQUEST_FILENAME} !-d
# append aff query string to URL and any existing query string
RewriteRule (.*) /?IBA=$1 [QSA,L]
# If request is not for html, htm, php, txt, gif, jpeg, jpg, or png files
RewriteCond %{REQUEST_URI} !\.(html?¦php¦txt¦gif¦jpe?g¦png)$
# and requested resource does not exist as a directory
RewriteCond %{REQUEST_FILENAME} !-d
# append aff query string to URL
RewriteRule (.*) /?IBA=$1 [L]
The html? pattern matches either htm or html, and jpe?g matches either jpg or jpeg. I also added an exclusion for .txt files, in case you have or will have a robots.txt file. These may not be needed now, but are good future-proofing.
Reemember to replace all broken pipe "¦" characters with solid pipes if you cut and paste this code -- posting on this board replaces solid pipes with broken ones, and mod_rewrite requires solid pipes.
Jim