Forum Moderators: phranque

Message Too Old, No Replies

Rename a directory

         

Toca

9:27 am on Aug 24, 2004 (gmt 0)

10+ Year Member



Hi,

I'd like to be able to rename a directory using the .htaccess file.

For example, say there's a file as follows:

dir1/hello.html

I'd like it to actually load dir2/hello.html, without the URL changing. The same would apply for all other files in dir1.

Is this possible?

Thanks.

jdMorgan

1:20 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Toca,

Welcome to WebmasterWorld!

Yes, what you need is an internal rewrite, as opposed to an external redirect.

The resources cited in our charter [webmasterworld.com] will get you started in the right direction.

Jim

Toca

1:56 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



Thanks. Would this be the right way to tackle it?

RewriteRule ^/dir1(.*)$ /dir2/$1 [R]

jdMorgan

2:06 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Close, but that is an external redirect, because you have included the [R] flag. Also there are two minor problems in the pattern. Try:

RewriteRule [b]^d[/b]ir1[b]/[/b](.*)$ /dir2/$1 [[b]L[/b]]


You'll also likely need to add

Options +FollowSymLinks
RewriteEngine on

ahead of your code.

Jim

Toca

2:18 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



I understand, thanks a lot.