开发者

Apache URL rewrite - Trying to mask the folder name

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开发者_JS百科 fails with a 404. How can I mask the folder name? :/


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]


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'); ?>


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]


RewriteEngine on
RewriteCond %{REQUEST_URI} !^subfolder/login
RewriteRule ^login/(.*)$ subfolder/login/$1 [L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜