Subdirectory Rewrites

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

Subdirectory Rewrites

Postby tecktalkcm0391 » Sun Aug 02, 2009 10:23 am

I have to directories that I want to make read a subdirectory. They are as follows:

site.com/associates/learn/ reads files in site.com/associates/learn/Mv1.9.4.19/

and

site.com/learn reads files in site.com/learn/Mv1.9.4.19/

I have this so far, but its not letting me get the the associates folder at all. I also would like it to redirect any both Mv1.9.4.19 folders to the correct location (site.com/learn/Mv1.9.4.19/ -> site.com/learn/)

Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.site\.com$
RewriteCond %{REQUEST_URI} !^/learn/Mv1.9.4.19/
RewriteRule (.*) /learn/Mv1.9.4.19/$1

RewriteCond %{REQUEST_URI} ^/learn/Mv1.9.4.19/
RewriteRule ^/learn/Mv1.9.4.19/(.*) /learn/$1 [R=301]


Thanks so much! I'm still starting to learn this.
tecktalkcm0391
 
Posts: 10
Joined: Tue Jun 19, 2007 7:51 pm
Location: In front of my computer... when I am online...

Postby richardk » Sun Aug 02, 2009 12:59 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(associates/)?learn/Mv1.9.4.19(/(.*))?$ /$1learn/$3 [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(associates/)?learn(/(.*))?$ /$1learn/Mv1.9.4.19/$3 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 32 guests

cron