Forum Moderators: phranque
i was wondering if someone can help me with a folder redirection.
i have this:
# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI}!^(/Projects/)?$
# Rewrite all those to insert /projects.
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ /projects/$1 [R,L]
Cause we recently had /Projects/ and /projects/ and we merged all the sub-folders together into the lower p, /projects/.
We want anyone that goes to /Projects/anything to be taken to /projects/anything - so we have a seemless upgrade to the site.
at the moment, that just writes:
www.mydomain.com/projects/projects/projects/projects/projects/Projects/myfolder/page3.html
Two ways to fix it:
1)
# Only apply to URLs that aren't already under /Projects or /projects folder.
RewriteCond %{REQUEST_URI} [b]!^(/[Pp]r[/b]ojects/)?$
# Rewrite those that do not exist in requested path to insert the /projects path.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /projects/$1 [L]
# Only apply this rule one time per HTTP request
RewriteCond %{ENV:Rewrite_Done} !^True$ [NC]
# Only apply to URLs that aren't already under /Projects folder.
RewriteCond %{REQUEST_URI} !^(/Projects/)?$
# Rewrite those that do not exist in requested path to insert the /projects path.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /projects/$1 [E=Rewrite_Done:True,L]
Note that it may be that the case of "Projects" is wrong in your original code. I wasn't sure from your description, so I'm assuming a less-simple problem, though.
Jim
what about something like:
RewriteCond %{REQUEST_URI}!^[P]rojects/$
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^.]+)\.([^/]+[^.]+)$http://%{HTTP_HOST}/$1/$2/$3/$4\.$5 [L]
RewriteRule ^([^/]+)/([^/]+)/([^.]+)\.([^/]+[^.]+)$ [%{HTTP_HOST}...] [L]
RewriteRule ^([^/]+)/([^.]+)\.([^/]+[^.]+)$ [%{HTTP_HOST}...] [L]
RewriteRule ^([^.]+)\.([^/]+[^.]+)$ [%{HTTP_HOST}...] [L]
so far i can't get this to work.
i need to take care of any extension, .html, .shtml, .jpg, .zip, etc
and i need to take care of no more than 4 folders after /Projects/
Sorry, missed the end-anchor on the first RewriteCond:
# Only apply to URLs that aren't already under /Projects or /projects folder, and are not "/".
RewriteCond %{REQUEST_URI} !^/([Pp]rojects/¦/$)
# Rewrite those that do not exist in requested path to insert the /projects path.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /projects/$1 [L]
Jim
[edited by: jdMorgan at 9:20 pm (utc) on May 17, 2007]
i am using the .htaccess in my top parent folder, .com/.htaccess
i don't want to create the .htaccess in the old folder /Projects - we don't want it to be there, to stop ourselves from posting files into this folder, when we only want to use the lower case, /projects/
Anyone see what the problem with the code is?
Also, it looks like there may be a problem with handling the "/" file, so try this tweaked RewriteCond:
# Only apply to URLs that aren't already under /Projects or /projects folder, and are not "/".
RewriteCond %{REQUEST_URI} [b]!^(/[[/b]Pp]rojects/¦/$)
# Rewrite those that do not exist in requested path to insert the /projects path.
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule (.*) /projects/$1 [L]
[edited by: jdMorgan at 2:49 am (utc) on May 30, 2007]