Welcome to WebmasterWorld Guest from 54.159.179.132

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)

5+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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)

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



QSA is implied anyway. Omit it.

You need to add [L] always.

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

5+ Year Member



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

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



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)

5+ Year Member



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)

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



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)

5+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month