[Help] Rewrite for a image host

Indrek

New Member
#1
Hi

I'd like to use this image host which I moved from apache.
http://codefuture.co.uk/projects/imagehost/

It uses a strange system and it WONT work without the rewrites.

Here's what the .htaccess looks like:

Code:
<IfModule mod_rewrite.c>
RewriteEngine on
    ErrorDocument 400 /index.php?err=400
    ErrorDocument 401 /index.php?err=401
    ErrorDocument 403 /index.php?err=403
    ErrorDocument 404 /index.php?err=404
    ErrorDocument 500 /index.php?err=500
#image view
    RewriteRule ^pm-(.*)\.(jpg|jpeg|png|gif|html)$ thumbnail.php?pm=$1 [L]
    RewriteRule ^pt-(.*)\.(jpg|jpeg|png|gif|html)$ thumbnail.php?pt=$1 [L]
    RewriteRule ^dt-(.*)\.(jpg|jpeg|png|gif)$ image.php?dt=$1 [L]
    RewriteRule ^dm-(.*)\.(jpg|jpeg|png|gif)$ image.php?dm=$1 [L]
    RewriteRule ^di-(.*)\.(jpg|jpeg|png|gif|bmp)$ image.php?di=$1 [L]
    RewriteRule ^dl-(.*)\.(jpg|jpeg|png|gif|bmp)$ image.php?dl=$1 [L]
   
    RewriteRule ^pm/(.*)/(.*)\.(jpg|jpeg|png|gif|html)$ thumbnail.php?pm=$1 [L]
    RewriteRule ^pt/(.*)/(.*)\.(jpg|jpeg|png|gif|html)$ thumbnail.php?pt=$1 [L]
    RewriteRule ^dt/(.*)/(.*)\.(jpg|jpeg|png|gif)$ image.php?dt=$1 [L]
    RewriteRule ^dm/(.*)/(.*)\.(jpg|jpeg|png|gif)$ image.php?dm=$1 [L]
    RewriteRule ^di/(.*)/(.*)\.(jpg|jpeg|png|gif|bmp)$ image.php?di=$1 [L]
    RewriteRule ^dl/(.*)/(.*)\.(jpg|jpeg|png|gif|bmp)$ image.php?dl=$1 [L]
#Not Found
    RewriteRule ^(pm|pt)/(.*)/(.*)$ thumbnail.php?pm=notfound [L]
    RewriteRule ^(dt|dm|di|dl)/(.*)/(.*)$ index.php?di=notfound [L]

#Gallery
    RewriteRule ^gallery/$ gallery.php [L]
    RewriteRule ^gallery/([0-9]+)/$ gallery.php?p=$1 [L]
    RewriteRule ^gallery/(.*)/([0-9]+)/$ gallery.php?p=$2&o=$1 [L]
    RewriteRule ^gallery/([A-Za-z])/page([0-9]+)\.html$ gallery.php?p=$2&o=$1 [L]
#sitemap
    RewriteRule ^sitemap.xml$ sitemap.php [L]
</IfModule>
I tried to add / before ^ but it didn't help.

If you have some time could you tell me where should I look for help?
 

Indrek

New Member
#2
I believe I posted to the wrong forum.. Can mod-s move it here? http://openlitespeed.com/forums/linux-support-debian-ubuntu-solusos-etc.12/

Ok this is what I did..

the image site is in /img sub folder

so here's the code I tried.. but it still does not work.. I just got MyBB rewrites working.. so there is still hope.

Code:
    RewriteRule ^/img/pm-(.*)\.(jpg|jpeg|png|gif|html)$ thumbnail.php?pm=$1 [L]
    RewriteRule ^/img/pt-(.*)\.(jpg|jpeg|png|gif|html)$ thumbnail.php?pt=$1 [L]
    RewriteRule ^/img/dt-(.*)\.(jpg|jpeg|png|gif)$ image.php?dt=$1 [L]
    RewriteRule ^/img/dm-(.*)\.(jpg|jpeg|png|gif)$ image.php?dm=$1 [L]
    RewriteRule ^/img/di-(.*)\.(jpg|jpeg|png|gif|bmp)$ image.php?di=$1 [L]
    RewriteRule ^/img/dl-(.*)\.(jpg|jpeg|png|gif|bmp)$ image.php?dl=$1 [L]
  
    RewriteRule ^/img/pm/(.*)/(.*)\.(jpg|jpeg|png|gif|html)$ thumbnail.php?pm=$1 [L]
    RewriteRule ^/img/pt/(.*)/(.*)\.(jpg|jpeg|png|gif|html)$ thumbnail.php?pt=$1 [L]
    RewriteRule ^/img/dt/(.*)/(.*)\.(jpg|jpeg|png|gif)$ image.php?dt=$1 [L]
    RewriteRule ^/img/dm/(.*)/(.*)\.(jpg|jpeg|png|gif)$ image.php?dm=$1 [L]
    RewriteRule ^/img/di/(.*)/(.*)\.(jpg|jpeg|png|gif|bmp)$ image.php?di=$1 [L]
    RewriteRule ^/img/dl/(.*)/(.*)\.(jpg|jpeg|png|gif|bmp)$ image.php?dl=$1 [L]

    RewriteRule ^/img/(pm|pt)/(.*)/(.*)$ thumbnail.php?pm=notfound [L]
    RewriteRule ^/img/(dt|dm|di|dl)/(.*)/(.*)$ index.php?di=notfound [L]


    RewriteRule ^/img/gallery/$ gallery.php [L]
    RewriteRule ^/img/gallery/([0-9]+)/$ gallery.php?p=$1 [L]
    RewriteRule ^/img/gallery/(.*)/([0-9]+)/$ gallery.php?p=$2&o=$1 [L]
    RewriteRule ^/img/gallery/([A-Za-z])/page([0-9]+)\.html$ gallery.php?p=$2&o=$1 [L]

    RewriteRule ^/img/sitemap.xml$ sitemap.php [L]
 
#3
Hi Indrek,

Sorry about such a late reply, I did not get a notification for this post for some reason.

Were you able to resolve your issue?

Kevin
 
#5
A couple notes:

In your first post, you mentioned that it is in an .htaccess file. You may already know this, but OLS does not work with .htaccess files, only enterprise does.

Also, in the vhost and context settings (depends on context type), you can enable rewrite logging to level '9'. This will output some log messages for you to determine which rule failed.

Lastly, and I kind of mentioned this with the second point, but if you set the images up as a context, (e.g. www.example.com/img/myimage.png), the context level rewrite rule will be given /myimage.png as the uri.

If none of these fix the issue, could you visit an example url and post the rewrite log messages? Edit out the bits you don't want public. You could also send me a pm if you'd rather not post it.
 

Indrek

New Member
#6
Yes I talked about the .htaccess that comes with the plugin. I know that OLS doesn't support it.
I have the log level at 9.

I'm not sure about the context images.

Here are my uploaded images
/usr/local/lsws/site.net/html/img/upload/images
site.net/img is the root folder

Script makes html sites for every image with rewrite like: site.net/img/pm/P6WJ/2016-07-21_02.html
There is no /pm/ folder in /img/ directory

I want the rewrites to apply only to site.net/img folder "/img" not for the whole domain

Here's the log

Code:
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/pm/P6WJ/2016-07-21_02.html' with pattern '^/img/pm-(.*)\.(jpg|jpeg|png|gif|html)$', result: -1
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/pm/P6WJ/2016-07-21_02.html' with pattern '^/img/pt-(.*)\.(jpg|jpeg|png|gif|html)$', result: -1
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/pm/P6WJ/2016-07-21_02.html' with pattern '^/img/dt-(.*)\.(jpg|jpeg|png|gif)$', result: -1
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/pm/P6WJ/2016-07-21_02.html' with pattern '^/img/dm-(.*)\.(jpg|jpeg|png|gif)$', result: -1
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/pm/P6WJ/2016-07-21_02.html' with pattern '^/img/di-(.*)\.(jpg|jpeg|png|gif|bmp)$', result: -1
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/pm/P6WJ/2016-07-21_02.html' with pattern '^/img/dl-(.*)\.(jpg|jpeg|png|gif|bmp)$', result: -1
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/pm/P6WJ/2016-07-21_02.html' with pattern '^/img/pm/(.*)/(.*)\.(jpg|jpeg|png|gif|html)$', result: 4
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Source URI: '/img/pm/P6WJ/2016-07-21_02.html' => Result URI: 'thumbnail.php?pm=P6WJ'
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] replace current query string with 'pm=P6WJ'
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Last Rule, stop!
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/pm-(.*)\.(jpg|jpeg|png|gif|html)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/pt-(.*)\.(jpg|jpeg|png|gif|html)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/dt-(.*)\.(jpg|jpeg|png|gif)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/dm-(.*)\.(jpg|jpeg|png|gif)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/di-(.*)\.(jpg|jpeg|png|gif|bmp)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/dl-(.*)\.(jpg|jpeg|png|gif|bmp)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/pm/(.*)/(.*)\.(jpg|jpeg|png|gif|html)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/pt/(.*)/(.*)\.(jpg|jpeg|png|gif|html)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/dt/(.*)/(.*)\.(jpg|jpeg|png|gif)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/dm/(.*)/(.*)\.(jpg|jpeg|png|gif)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/di/(.*)/(.*)\.(jpg|jpeg|png|gif|bmp)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/dl/(.*)/(.*)\.(jpg|jpeg|png|gif|bmp)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/(pm|pt)/(.*)/(.*)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/(dt|dm|di|dl)/(.*)/(.*)$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/gallery/$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/gallery/([0-9]+)/$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/gallery/(.*)/([0-9]+)/$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/gallery/([A-Za-z])/page([0-9]+)\.html$', result: -1
2016-08-09 17:27:16.141 [INFO] [REDACTED] [REWRITE] Rule: Match '/img/gallery.php' with pattern '^/img/sitemap.xml$', result: -1
Anything else or any idea what I should do?
I know it's a stupid script but I need the old image links to work.

Thank You! :)

EDITED BY lsfoo: Removed sensitive information from log.
 
Last edited by a moderator:

lsfoo

Moderator
#7
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] Source URI: '/img/pm/P6WJ/2016-07-21_02.html' => Result URI: 'thumbnail.php?pm=P6WJ'
2016-08-09 17:27:14.122 [INFO] [REDACTED] [REWRITE] replace current query string with 'pm=P6WJ'

Per these lines, it looks like it matched correctly.

Is the replacement text correct?
In other words:
is the page supposed to be site.net/thumbnail.php or site.net/img/thumbnail.php

If it is supposed to be the latter, then you need to add img/ before thumbnail.php in the rewrite rules.
 

Indrek

New Member
#8
It's supposed to be /img

And it works now.. (y)

Amazing, such a simple mistake.

Thank you very much, OLS is the best!! :love:

I guess this thread can now be closed. Solved.
 
Top