Welcome to WebmasterWorld Guest from 54.145.15.88

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Force requests to a sub-directory

     
12:28 am on Dec 30, 2009 (gmt 0)

New User

5+ Year Member

joined:Dec 23, 2009
posts: 17
votes: 0


Hello,

I've been trying to for site.com/<whatever page is requested here> to site.com/dir/<whatever page is requested here>, but I seem to be out of luck.

here's my code:
RewriteCond %{HTTP_HOST} !site.com [NC]
RewriteRule (.*) [site.com...] [R=301,L]

Ideas?

Regards,

Air

3:43 am on Dec 30, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 10, 2000
posts:1253
votes: 0


make the necessary substitutions to directory, and domain, should work;

RewriteEngine ON
RewriteCond %{REQUEST_URI} !^/?directory
RewriteRule ^(.+)?$ http://example.com/directory/$1 [QSA,R=301]

8:22 am on Dec 30, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


QSA is implied anyway. Omit it.

You need to add [L] always.

9:12 am on Jan 15, 2010 (gmt 0)

New User

5+ Year Member

joined:Dec 23, 2009
posts:17
votes: 0


It worked great, thank you guys.
5:20 pm on Jan 15, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


A remaining question is whether you actually wanted a redirect, which exposes the new filepath as a URL to the client (and forces all the search engines to toss all your old URLs), or whether you simply want to move the files that those old URLs correspond to into a sub-directory, changing where the 'content' for those old URLs is stored, but not changing the URLs themselves.

If that's the case, then you want an internal rewrite, not an external redirect, and the code will need to be tweaked.

Jim

6:07 pm on Jan 15, 2010 (gmt 0)

New User

5+ Year Member

joined:Dec 23, 2009
posts:17
votes: 0


Jim,
I wanted an internal rewrite actually. And it worked (you gave me a great code in a previous post). But having the internal rewrite & that old code together didn't work.

And the new website has new contents, so what the search engines have will be different from what is there now anyway.
However, if you have a better solution, it would be so great to share
it.

6:45 pm on Jan 15, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


The usual problem when 'new code' doesn't work with 'old code' is that the new code has been inserted in the wrong place. See this concurrent thread, and look for the list I posted showing mod_rewrite rule-ordering [webmasterworld.com].

Jim

6:53 pm on Jan 15, 2010 (gmt 0)

New User

5+ Year Member

joined:Dec 23, 2009
posts:17
votes: 0


Jim,

Thanks again for the resource. I should take my time reading & trying things out. If I happen to not get it done properly, I shall ask again.

Thank you very much.

--Ex

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members