homepage Welcome to WebmasterWorld Guest from 54.197.94.241
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess question
when a subdirectory is a different domain
Boaz




msg:1499694
 2:27 pm on Jul 21, 2005 (gmt 0)

Suppose there are two sites, www.domain1.com and www.domain2.com. For various reasons, www.domain2.com is mapped to a subdirectory of www.domain1.com (so physically, the files of domain2 are in a subdirectory of domain1, but when someone calls domain2 he of course doesn't see that, he sees only www.domain2.com).

The problem?
I'd like to redirect any request for [domain1.com...] to [domain1.com....]
Normally I'd set up an htaccess file as follows:

RewriteEngine on
RewriteCond %{HTTP_HOST}!^www\.domain1\.com
RewriteRule (.*) [domain1.com...] [R=301,L]

But - if I'd do this in this case, any request for [domain2.com...] pages will redirect to [domain1.com...] ...

So - any idea what I need to change in my htaccess file so only requests for domain1 will redirect, and not requests for domain2?

Thanks,
Boaz

 

jdMorgan




msg:1499695
 3:03 pm on Jul 21, 2005 (gmt 0)

Your first RewriteCond is a negative match -- That's what the "!" is there for. Any domain *not* equal to "www.domain1.com" is redirected to "www.domain1.com".

To avoid your current problem, simply change the RewriteCond pattern to a positive match for the domain that you *do* wish to redirect, making it "^domain1\.com" instead of "!^www\.domain1\.com".

See the mod_rewrite and regular expressions documentation cited in our forum charter.

Jim

Boaz




msg:1499696
 6:12 pm on Jul 21, 2005 (gmt 0)

thanks!

alexo




msg:1499697
 9:30 pm on Jul 25, 2005 (gmt 0)

Hello

i have a question about htaccess file

i'm using Pmachine CMS, on which u can view the same article using different files

for example
domain.com/more.php?id=503_0_3_0_M

and

domain.com/stuff.php?id=503_0_3_0_M

i did 4 months ago modrewrite and now my files have this look

domain.com/more/503_0_3_0_M/

domain.com/stuff/503_0_3_0_M/

503 (is article number)
3 (weblog number)
------
avoiding duplicate content, now i need to redirect all users who come with stuff/***_0_*_0_M/ to more/***_0_*_0_M/

need advice how to do it?

i try such a code, but it seems don't work

RewriteEngine On

RewriteRule /stuff/([A-Za-z0-9_]+)/ /more/$1/ [R=301]

what i'm doing wrong.

thx

jdMorgan




msg:1499698
 8:07 pm on Jul 26, 2005 (gmt 0)

Where did you put this code, in httpd.conf, or in .htaccess?

In .htaccess, you'll need:

Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^stuff/([A-Za-z0-9_]+)/$ /more/$1/ [R=301,L]

Note: You may or may not need the Options directive at the beginning. I included it in case you need it. Try the code with and without that line.

Jim

alexo




msg:1499699
 11:19 pm on Jul 26, 2005 (gmt 0)

jdMorgan

great thx

alexo




msg:1499700
 11:27 pm on Jul 26, 2005 (gmt 0)

can i ask another question?

i know that 301 redirect is allowed by google, but is it so bad, when ur htaccess file is more than 10kb file?

(i put a lot of redirects, modrewrite) and afraid, that it may cause any problem .. (for example speed will be slow and something more serious)

thank you

jdMorgan




msg:1499701
 11:36 pm on Jul 26, 2005 (gmt 0)

This depends on how busy your site is. At less than 10,000 unique visitors per day, a 10kB .htaccess probably won't be a problem. I have sites where the .htaccess files grow to 48kB occasionally, and there's no noticeable effect on server performance.

You might be able to combine several or many of your rewrites and redirects into just a few by making better use of mod_rewrite's regular-expressions-based pattern-matching and back-referencing capability.

Jim

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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved