Forum Moderators: phranque

Message Too Old, No Replies

.htaccess help

seems to be the hot topic

         

Tearabite

4:46 pm on Mar 11, 2006 (gmt 0)

10+ Year Member



Here's me trouble:

I have 2 domains. Domain one is my primary, and domain two is a subdirectory of domain 1, with a redirect to the subdomain.

The problem is that on domain2, ALL requests for pages go to the index.php page. this is usually fine, unless i'm trying to leave a sitemap for google to pickup, or if i want to be able to manually open a HTML page in the domain - since EVERYTHING gets directed to index.php i cant do this currently.

here is my .htaccess from domain1 (domain1 stuff left out, just the redirect part)

RewriteBase /
RewriteCond %{HTTP_HOST} domain2.com
RewriteCond %{REQUEST_URI}!domain2/
RewriteRule ^(.*)$ domain2/$1 [L]

and this is what's in domain2's .htaccess
<Files Settings.php>
Deny from all
</Files>

Tearabite

12:07 am on Mar 12, 2006 (gmt 0)

10+ Year Member



well, i've spent the entire afternoon reading up on ReWriteCond, and such, so now at least i have a basic understanding of how it works, and what i really want to do..

it's my understanding that the code i posted above simply redirects any incoming requests to domain2.com to the /domain2 folder, which has index.php set as the default.

all i need is a conditional statement that says something like:
IF you want domain2.com/sitemaps/sitemap.php, then go directly to /domain2.com/sitemaps/sitemap.php
ELSE send everything to domain2.com/index.php

at least now i understand what it is i really need.. i just need help with the syntax - which seems like it would be easy..
I got close by adding this in front of the current RewriteCond statements:

RewriteCond %{HTTP_HOST} domain2.com
RewriteCond %{REQUEST_URI}!domain2/sitemaps/
RewriteRule ^(.*)$ domain2/sitemaps/sitemaps.php$1 [L]

but this ended up sending EVERYTHING to /sitemaps.php

i think i'm close.. i guess i just need help with the syntax..

jdMorgan

6:27 pm on Mar 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you probably need is an *exclusion* so that specific types of requests *are not* rewritten. Your first example above had an error in the second RewriteCond -- the one intended to create just such an exclusion. If this is fixed, you probably don't need to take any extra steps:

RewriteBase /
RewriteCond %{HTTP_HOST} domain2\.com
RewriteCond %{REQUEST_URI} [b]!^/do[/b]main2/
RewriteRule ^(.*)$ domain2/$1 [L]

which can also be rewritten in this specific case as:

RewriteBase /
RewriteCond %{HTTP_HOST} domain2\.com
RewriteCond [b]$1 [i][/i]!^do[/b]main2/
RewriteRule (.*) /domain2/$1 [L]

Note that URLs 'seen' by RewriteRule in an .htaccess (per-directory) context do not start with a slash, while those in %{REQUEST_URI} always do.

Jim

Tearabite

1:50 am on Mar 16, 2006 (gmt 0)

10+ Year Member



JD! you are the rewrite KING!
Thanks to you, that solved my problem! .. mostly..

i guess i failed to mention that i also need to open a file in a subdirectory also..

NOW if i open say, [mysite...] it opens (it would not before)
but i also need to open [mysite...]
when i try this, i just get my index page (like before)

I assume i need another entry in .htaccess that specifies this, but of course i'm clueless on how to do it..

jdMorgan

2:17 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So add another RewriteCond, excluding that directory or filepath, as shown for "domain2/" above...

To avoid being obtuse, I should note that our purpose here is to help you learn, and not to write your code for you. We simply don't have enough contributing member volunteers in this forum to meet the global demand for free code... ;)

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

Tearabite

2:38 am on Mar 16, 2006 (gmt 0)

10+ Year Member



i understand.. i'll give it a shot..

Tearabite

5:20 am on Mar 16, 2006 (gmt 0)

10+ Year Member



give a man a fish and he'll eat for a day..
TEACH a man to fish.. and he'll starve to death..

ok.. sounded simple enough.. here is what i tried:

RewriteBase /
RewriteCond %{HTTP_HOST} mysite.com
RewriteCond %{REQUEST_URI}!^/mysite/
RewriteCond %{REQUEST_URI}!^/mysite/sitemaps/
RewriteRule ^(.*)$ bigbraggers/$1 [L]

(also tried!^mysite/sitemaps/sitemaps.php )

and still, all i get is my index page.. however, if i access it this way:
[mysite.com...] it works
Note the double mysite, which doesnt really exist - the actual path is : ..primarysite/htdocs/mysite/sitemaps

my eyes are bleeding from reading the apache documentation - am i doing it wrong, or is something else fubar'd?