Forum Moderators: phranque

Message Too Old, No Replies

Rewrite For Pages

moved from /directories/ to root

         

old_expat

9:49 am on Dec 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm moving some of my pages from several directories back to the root folder and want to put a rewrite statement in my root .htaccess file

I'm wondering if this will work:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^www.mysite.com/this-directory1/ www.mysite.com/
RewriteRule ^www.mysite.com/this-directory2/ www.mysite.com/
RewriteRule ^www.mysite.com/this-directory3/ www.mysite.com/

or can somone point out a simpler/better way?

jdMorgan

1:41 pm on Dec 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to redirect each page in the old directory to the same-named page in the root, then you'll need to tell mod_rewrite to do that:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^this-directory1/(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^this-directory2/(.*)$ http://www.example.com/$1 [R=301,L]
RewriteRule ^this-directory3/(.*)$ http://www.example.com/$1 [R=301,L]

Note additional syntax corrections.

Jim

old_expat

4:39 pm on Dec 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you, Jim. :)

g1smd

11:59 pm on Dec 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Would this be any more efficient?

RewriteRule ^(this¦that¦other¦whatever)/(.*)$ http://www.example.com/$1 [R=301,L]

jdMorgan

1:07 am on Dec 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For use in .htaccess, yes it would be, but the parentheses need to be nested to properly define the $1 back-reference:

RewriteRule ^((this-directory1¦this-directory2¦this-directory3)/.*)$ http://www.example.com/$1 [R=301,L]

Replace the broken pipe "¦" characters in the code with solid pipe characters before use' Posting on this forum modifies the pipe characters.

Jim