Forum Moderators: phranque

Message Too Old, No Replies

Mod_rewrite Help changing directories

Mod_rewrite Help changing directories

         

Nosmada

6:54 am on Jan 21, 2004 (gmt 0)

10+ Year Member



I need to change the folder that a whole directory is in from:

[yoursite.com...]

to the root:

[yoursite.com...]

We are talking like 500,000 folders in the directory folder all moved to the root.

I can't find the mod_rewrite example for this directive but I really need to so the search engines just seamlessly go to the directory in the new location which is the root. I take it the code goes in .htaccess?

Looking forward to your answers.

jdMorgan

6:59 am on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nosmada,

Welcome to WebmasterWorld [webmasterworld.com]!

Here's a good place to start: Introduction to mod_rewrite [webmasterworld.com]

Also, please read our Apache Forum Charter [webmasterworld.com] to help you get oriented here.

Thanks!
Jim

Nosmada

5:09 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



Thanks for the welcome jdMorgan and the info. I've looked through it and have a question. Removed FP extensions through Plesk for my dedicated server and made sure that mod_rewrite is in place. Just attempting the very simple example from DaveAtIFG - I put the following in .htaccess and place in root of mysite.com:

RewriteEngine on
RewriteRule ^page1\.shtml$ page2.shtml [R=301,L]

So I load page 1

[mysite.com...]

...and get

[mysite.com...]

...so as you can see there is a redirect of sorts but it is tacking on the full path to the root URL?

hakre

5:13 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



checkout RewriteBase and place it after rewriteengine on.

for a start

RewriteBase /

might do the job ;)

Nosmada

5:24 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



Thanks hakre. Tried the following and same thing happens as before? Here is what I tried:

RewriteEngine on RewriteBase /
RewriteRule ^page1\.shtml$ page2.shtml [R=301,L]

Birdman

5:28 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try putting the rewriteBase rule under rewriteEngine.

RewriteEngine on
RewriteBase /
RewriteRule ^page1\.shtml$ page2.shtml [R=301,L]

Nosmada

5:34 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



Haha. Got it. For fun tried a / before the second page...like this:

RewriteEngine on RewriteBase /
RewriteRule ^page1\.shtml$ /page2.shtml [R=301,L]

My other question which I have been searching for to no avail yet is I need to redirect everything in a particular directory up into the root. So for example:

[mysite.com...]

gets redirected to...

[mysite.com...]

and this...

[mysite.com...]

gets redirected to...

[mysite.com...]

hakre

5:49 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it's quite the same:

RewriteRule ^/directory/(.*)$ /$1 [R=301,L]

i guess this should do the job.

jdMorgan

6:02 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That code should work fine in httpd.conf. For use in .htaccess, remove the leading slash on the pattern:

RewriteRule ^directory/(.*)$ /$1 [R=301,L]

Jim

Nosmada

6:07 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



Thanks hakre but didn't work?

Nosmada

7:04 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



Thanks to all. Removing the leading slash on the pattern did it. Sweet success. Do I just check server stats to see how long I wait to remove the abandoned pages? Or can I remove them right now. Which is better for Google and other engines?

jdMorgan

7:45 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because your redirect will kick in before any content is served, they are already inaccessible, so there's no need to leave them on the server if you need the space for something else.

Jim

Nosmada

8:15 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



Thanks Jim. How do I know how long to leave the redirect there for? My guess is indefinitely becuase over time the search engines will call the nonexistant pages less and less? Just thinking about how to minimize the redirect using up valuable CPU.