Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite to Subfolders

Mod Rewrite to Subfolders

         

walker6o9

10:25 pm on Sep 25, 2008 (gmt 0)

10+ Year Member



RewriteEngine On
RewriteRule ^(.*)/$ index.php?pic=$1
RewriteRule ^[^/.]+\.(jpg¦gif¦png¦jpeg)$ %{REQUEST_URI}/ [R=301,L]

So I'm using the above rule to rewrite files that look like this:
www.mySite.com/folder1/folder2/index.php?pic=1.jpg

to look like this:
www.mySite.com/mainFolder/subFolder/1.jpg/

This rules works great. The problem I am having is that I would prefer to put the .htaccess file that I currently put in mainFolder, in subFolder, so that I can apply this any other folders that are created later on, without having to add .htaccess files, because the people who will be creating the folders in the future lack the technical abilities to create and write .htaccess files.

Is there a rule that will allow me to put the above .htaccess folder, which currently resides in subFolder, into mainFolder, and still have these rules work?

jdMorgan

3:52 pm on Sep 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add "subfolder/" to the beginning of the pattern in both rules.

Your first rule should have an "[L]" flag on it, to promote efficiency.

Also, be aware that adding a slash to the end of a filepath is 'bad form' according to the HTTP specification, since it implies that the URL designates a directory or the index page of a directory. You may have trouble with optimal search engine indexing of these unorthodox URLs in the future. As a result, I would recommend that you re-consider your motivation for adding these slashes to the end of image URLs.

x.z indicates a 'page' or an 'object' on a page.
xyz/ indicates a directory (or by extension, a directory index page).

Jim

g1smd

3:56 pm on Sep 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Once you have got the rewrite working, what happens if i continue trying to ask for this URL from your server?

www.mySite.com/folder1/folder2/index.php?pic=1.jpg

Does it still deliver the content, or does it tell me that it is now at a new *URL*?