Need assistance with my .htaccess / mod-rewrite

New to mod_rewrite? This is a good place to start.

Postby Guest » Thu Jan 13, 2005 8:24 am

Caterham wrote:yes, you've to change the links pointing to the images etc., but you can also use mod_rewrite to rewrite the image-dir:

If you've example.com/images

Code: Select all
RewriteRule ^.+images/(.*)$ /images/$1 [L]
to rewrite eg. example.com/index/images to example.com/images

Bob

Hello Robert,

This is wonderful. The above worked nicely. The only thing I would need to do is place all of my other resources, such as: css, swf, ico, and js files into another directory, perhaps "resources", and then use another line like the one above modified to point to that directory to pull in the files that are not in the images directory.

You should totally right a book! :) I tell ya, this forum has been such a great resource for mod-rewrites.

Thank you so much again for your help!
-Victor
Guest
 

Postby Caterham » Thu Jan 13, 2005 9:17 am

Hi Victor,

well you can use
Code: Select all
RewriteRule ^.+(images|scripts|files)/(.*)$ /$1/$2 [L]
to rewrite some more folders to the doc root folder. Or you use individual rules such as
Code: Select all
RewriteRule ^.+images/(.*)$ /images/$1 [L]
RewriteRule ^.+scripts/(.*)$ /scripts/$1 [L]


Just one final note: If you are running apache >1.3.28 or >2.0.45 with more than 9 name-value pairs (variables), you might have to use
Code: Select all
RewriteOptions MaxRedirects=25
in your .htaccess to increase the maximum number of redirects from the default value 10 to 25 (these are so called internal redirects). This is an apache prevention for endless loops.

You should totally right a book!
Well, I wrote already some sort of mod_rewrite FAQ in a german forum, modrewrite.de :multi:

Robert
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby Guest » Thu Jan 13, 2005 12:14 pm

Hello Robert,

Caterham wrote:well you can use
Code: Select all
RewriteRule ^.+(images|scripts|files)/(.*)$ /$1/$2 [L]
to rewrite some more folders to the doc root folder. Or you use individual rules such as
Code: Select all
RewriteRule ^.+images/(.*)$ /images/$1 [L]
RewriteRule ^.+scripts/(.*)$ /scripts/$1 [L]


Thanks for the tip. It's nice to know that I can have one line to account for many different resource locations.
Caterham wrote:Just one final note: If you are running apache > 2.0.45 with more than 9 name-value pairs (variables), you might have to use
Code: Select all
RewriteOptions MaxRedirects=25
in your .htaccess to increase the maximum number of redirects from the default value 10 to 25 (these are so called internal redirects). This is an apache prevention for endless loops.

I am using less than 9 name-value pairs, and do not think I'll come close to the limit. If I do, and I notice to site acting weird, I'll be sure to place this in my .htaccess. Again, thanks for the tip! :)
Caterham wrote:Well, I wrote already some sort of mod_rewrite FAQ in a german forum, modrewrite.de :multi:

Too bad I don't understand German. :) Perhaps when you have time, you can translate it into an English version as well? :wink:

Best,
-Victor
Guest
 

Previous

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 95 guests

cron