Page 1 of 1
How can i use mod_rewrite to do following:
Posted: Thu Jun 08, 2006 9:54 am
by fastfingertips
Posted: Fri Jun 09, 2006 12:37 am
by RobertGonzalez
This is kinda janky, but it will act as a rewriter for any image name in that long folder you presented and pipe it to the short one. I think.
Code: Select all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=1]
RewriteRule ^backend/group/templates/backend/images/(.+)$ /templates/backend/images/$1 [QSA,L]
</IfModule>
Posted: Fri Jun 09, 2006 1:24 am
by fastfingertips
My problem is that i have to make that working with:
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.+) backend/$1/ [R=301,L]
RewriteRule ^(.*)/(.*)/(.*)/$ backend/index.php?page=$1&action=$2&$3 [L]
RewriteRule ^(.*)/(.*)/$ backend/index.php?page=$1&action=$2 [L]
RewriteRule ^(.*)/$ backend/index.php?page=$1 [L]
My problem is following: when i'm using mod_rewrite to create fancy URL's i cannot use relative image links because apache is taking the url and is adding to it the image path (and that is not a valid path to image).
For example, like this is looking a url of my page, index php is acting like front controller:
http://localhost/backend/group/
and when i'm using relative paths, that look like: templates/backend/images/edit.gif instead of taking the image as it is (since i'm located in root) he concates this path to what i have in URL:
http://localhost/backend/group/template ... s/edit.gif
Proper link to image is:
http://localhost/backend/templates/back ... s/edit.gif
Is there any way to avoid URL rewriting for images?
Posted: Fri Jun 09, 2006 1:30 am
by RobertGonzalez
I just ran across that issue in a site I am creating. What I did was, in my common include and utility page, was to create an absolute URL to preprend my image paths to, so through my scripts, I always referenced
http://www.mysite.com/images for my imagedir. Takes the hassle out of trying use rewrite rules for image linking.
I am not so sure that what you want to do is going to work with mod_rewrite anyway. I think MRW works with URLs thrown to the address bar, not in the actual printed html.
Posted: Fri Jun 09, 2006 1:34 am
by fastfingertips
What MRW is, please explain me to take some books to find out.
Posted: Fri Jun 09, 2006 1:36 am
by RobertGonzalez
Sorry, I was too lazy to actually spell out Mod-ReWrite (MRW).