views:

225

answers:

3

I have a website located at example.com/cmsFolder which I want to move to example.com/newFolder. I can't manually move this as it completely breaks this stupid CMS.

So I'm trying to use mod_rewrite to mask the folder name and keep it looking nice.

RewriteEngine on
RewriteRule ^cmsFolder/(.*)$ /newFolder/$1 [L]

That fails with a 404. How can I mask the folder name? :/

+4  A: 

Try this, It works for me while adding this rules to Apache's main configuration file:

RewriteEngine on
RewriteRule ^/cmsFolder/(.*)$ /newFolder/$1 [L]

I think you forgot first slash before cmsFolder. If you want to look at mod_rewrite logs:

RewriteLog "_PATH_TO_YOUR_\rewrite.log"
RewriteLogLevel 9

As Paolo comments log directives are not allowed in .htacces. Easy to understand why :-)

Edit:

Probably if you want to mask the request you will use [P] modifier (Proxy):

RewriteEngine on
RewriteRule ^/cmsFolder/(.*)$ /newFolder/$1 [P]
SourceRebels
Nice. I had no idea that there was a "RewriteLog" directive. This is certainly better than the guess and check method.
jamieb
Note the log directives can only go in the .conf files, they're not allowed in .htaccess files.
Paolo
Thanks, I never use .htaccess files because I'm just using Apache for personal purposes. I will modify my response with this info if you agree :-)
SourceRebels
When mod_rewrite is used in a .htaccess file, the local path prefix is removed from the URL path before before testing the rules. And the local path prefix for the root directory is `/`. That means all patterns must be written without that path prefix. So tab’s pattern actually was correct.
Gumbo
A: 

If you want to rewrite requests to /newFolder/… internally to /cmsFolder/…, you need to go the other way round:

RewriteEngine on
RewriteRule ^newFolder/(.*)$ /cmsFolder/$1 [L]
Gumbo
+1  A: 

An even simpler solution may be just to symlink the newFolder to cmsFolder

ln -s cmsFolder/ newFolder

Or you can create a short PHP script if you don't have shell access:

<?php symlink('cmsFolder','newFolder'); ?>
Paolo
Nice solution. You need to place 'Options FollowSymLinks' at your Apache configuration. If not this solution won't work. +1.
SourceRebels
True, thanks for the correction
Paolo