How can i use mod_rewrite to do following:

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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>
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

What MRW is, please explain me to take some books to find out.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry, I was too lazy to actually spell out Mod-ReWrite (MRW).
Post Reply