homepage Welcome to WebmasterWorld Guest from 54.198.224.121
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Force requests to a sub-directory
Excalibur




msg:4051081
 12:28 am on Dec 30, 2009 (gmt 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




msg:4051187
 3:43 am on Dec 30, 2009 (gmt 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]

g1smd




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

QSA is implied anyway. Omit it.

You need to add [L] always.

Excalibur




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

It worked great, thank you guys.

jdMorgan




msg:4061505
 5:20 pm on Jan 15, 2010 (gmt 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

Excalibur




msg:4061537
 6:07 pm on Jan 15, 2010 (gmt 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.

jdMorgan




msg:4061563
 6:45 pm on Jan 15, 2010 (gmt 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

Excalibur




msg:4061570
 6:53 pm on Jan 15, 2010 (gmt 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved