Forum Moderators: phranque
http://www.example.com/subfolder1/subfolder2/
I want to completely remove subfolder1 from the URL using mod_rewrite. I do NOT want to actually DELETE the folder, I just don't want users to see that it is there in the URL.
How do I do that? Thanks,
[edited by: jdMorgan at 5:01 pm (utc) on Jan. 22, 2009]
[edit reason] example.com [/edit]
No-one has mentioned RewriteBase here, and it should not be needed.
You also will need a RewriteCond to prevent recursion:
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond $1 !^subfolder2/
RewriteCond ^subfolder1/(.*)$ /subfolder1/subfolder2/$1 [L]
Once this is installed and tested, change all of the links that appear on your pages to remove "subfolder2/" from the URLs.
An optional third step is to detect client requests for /subfolder1/subfolder2/ URLs, and externally redirect them to /subfolder1/ URLs. This third step is optional, and is not the "fix" for what you are doing here. Changing your on-page links is NOT optional. We can discuss this third step later after you get the first two steps installed, tested, and working.
Jim
Otherwise it looks good. Check if you need a RewriteCond to prevent looping, as the output might re-match as a new input.
You'll also need a redirect such that should someone directly ask for the old location, their browser is redirected to the new location.
> post delayed 4 hours.
However, your rule will loop forever. You'll need a RewriteCond as well as perhaps making the .* pattern more specific.
You rule will generate a 302 redirect, so add [R=301,L] to make it a 301. Don't forget that pesky [L]. Always add one of those.
Finally, if you are already using RewriteRule in your file, then make all of your rules using RewriteRule. Mixing Redirect and RedirectMatch in the same file as RewriteRule can have unintended consequences.