Creating a rewriteCond in .htaccess
Moderator: kfury77
- chrisjlocke
- Top Contributor
- Posts: 995
- Joined: Mon Aug 01, 2005 4:12 pm
- Location: Essex, UK
- Contact:
Creating a rewriteCond in .htaccess
I've a php script which creates thumbnail images, which is part of the CMS of my website. However, this also means I can't use it directly within vB or phpBB forums, as [img]script.php?image=xyz.jpg[/img] just doesn't work.
What I'd like to do is create a 'fake' file, eg, http://www.creapsoft.co.uk/thumbs/chris ... 8/file.jpg
which (via .htaccess) will be re-written as http://www.creapsoft.co.uk/protectedima ... &width=200
Could it be done? Could someone give me some pointers please?
What I'd like to do is create a 'fake' file, eg, http://www.creapsoft.co.uk/thumbs/chris ... 8/file.jpg
which (via .htaccess) will be re-written as http://www.creapsoft.co.uk/protectedima ... &width=200
Could it be done? Could someone give me some pointers please?
.htAccess Help
Chris,
Yes, something like this can be done. If you still would like some help with this, let me know.
Tony
Yes, something like this can be done. If you still would like some help with this, let me know.
Tony
- chrisjlocke
- Top Contributor
- Posts: 995
- Joined: Mon Aug 01, 2005 4:12 pm
- Location: Essex, UK
- Contact:
Hi Tony,
Yup, am still struggling with this. I downloaded RegexBuddy to try and get a grasp on regular expressions (great program!) but don't know enough yet to see how I can do what I want.
Yup, am still struggling with this. I downloaded RegexBuddy to try and get a grasp on regular expressions (great program!) but don't know enough yet to see how I can do what I want.
.htaccess Support
Although I have never really found any outstanding documentation or tutorial for Apache URL Rewriting or other such .htaccess capabilities, the Apache documentation is decent, but not necessarily user-friendly:
Apache 1.3 (Apache 2.0 Guides also available, but almost the same functionality):
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
Other Useful References:
http://www.askapache.com/htaccess/mod_r ... ricks.html
http://www.htaccesselite.com/htaccess/
http://www.htaccesselite.com/htaccess/m ... vt101.html
The above references should get you going in the right direction, but I can also offer a little extra help.
I am sure this can be done several different ways, but here is one implementation to try:
- The basic layout of the .htaccess file:
- Place your .htaccess file in a directory above the directory referencing the "fake" files, such as
http://www.creapsoft.co.uk/thumbs/
- Test and good luck
I imagine the sample file is not exactly correct, but hopefully it will be able to lead you in the right direction.
Apache 1.3 (Apache 2.0 Guides also available, but almost the same functionality):
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
Other Useful References:
http://www.askapache.com/htaccess/mod_r ... ricks.html
http://www.htaccesselite.com/htaccess/
http://www.htaccesselite.com/htaccess/m ... vt101.html
The above references should get you going in the right direction, but I can also offer a little extra help.
Concerning your fake file setup, I use something similar in one of my projects and the cool thing is you do not even have to actually create the "fake" files.What I'd like to do is create a 'fake' file, eg, http://www.creapsoft.co.uk/thumbs/chris ... 8/file.jpg
which (via .htaccess) will be re-written as http://www.creapsoft.co.uk/protectedima ... &width=200
I am sure this can be done several different ways, but here is one implementation to try:
- The basic layout of the .htaccess file:
Code: Select all
# Chris's .htaccess File
# FollowSymLinks is required to run the RewriteEngine, so enable the
# option
Options -Indexes
Options +FollowSymLinks
# Activate the RewriteEngine
RewriteEngine On
# You may need to define the RewriteBase, depending on how your file
# paths relates to your web paths - see documentation
# I do not do this in my setup
#RewriteBase /
# Rewrite URL for CMS Thumbs
# Use RewriteCond to verify the URL should be redirected to thumbs
# This may not be necessary
# RewriteCond
# Rewrite Rule
RewriteRule /thumbs/(.*) /(.*)/(.*)\.jpg$
protectedimage.php?image=$1/$3.jpg_$2&cachedimage=true&width=200 [L]
# This [L] flag means this is the last rule to process
# You may want to check out some of the other flags
- Place your .htaccess file in a directory above the directory referencing the "fake" files, such as
http://www.creapsoft.co.uk/thumbs/
- Test and good luck
I imagine the sample file is not exactly correct, but hopefully it will be able to lead you in the right direction.
- chrisjlocke
- Top Contributor
- Posts: 995
- Joined: Mon Aug 01, 2005 4:12 pm
- Location: Essex, UK
- Contact:
- chrisjlocke
- Top Contributor
- Posts: 995
- Joined: Mon Aug 01, 2005 4:12 pm
- Location: Essex, UK
- Contact:
So far I've got this, but the server doesn't appear to be catching it.
RewriteRule /thumbs/(.*)/(.*)\.jpg_(.*)\.jpg$ /protectedimage.php?image=$1/$2.jpg_$3&cachedimage=true&width=200 [R=301,L]
I've had to tweak the URL slightly from my opening post. The URL I'm passing it is http://www.creapsoft.co.uk/thumbs/chris ... 012008.jpg and it should be re-mapping it to http://www.creapsoft.co.uk/protectedima ... &width=200
You've certainly led me in the right direction, and RegexBuddy confirms it *should* be working, but I don't know why it isn't. All I'm getting is a 404. Its not clear from the weblogs why though - just that the URL passed couldn't be found (rather than the rejigged URL being wrong).
RewriteRule /thumbs/(.*)/(.*)\.jpg_(.*)\.jpg$ /protectedimage.php?image=$1/$2.jpg_$3&cachedimage=true&width=200 [R=301,L]
I've had to tweak the URL slightly from my opening post. The URL I'm passing it is http://www.creapsoft.co.uk/thumbs/chris ... 012008.jpg and it should be re-mapping it to http://www.creapsoft.co.uk/protectedima ... &width=200
You've certainly led me in the right direction, and RegexBuddy confirms it *should* be working, but I don't know why it isn't. All I'm getting is a 404. Its not clear from the weblogs why though - just that the URL passed couldn't be found (rather than the rejigged URL being wrong).
- chrisjlocke
- Top Contributor
- Posts: 995
- Joined: Mon Aug 01, 2005 4:12 pm
- Location: Essex, UK
- Contact:
- chrisjlocke
- Top Contributor
- Posts: 995
- Joined: Mon Aug 01, 2005 4:12 pm
- Location: Essex, UK
- Contact: