Forum Moderators: phranque

Message Too Old, No Replies

rewrites from "pointed" domain to subdomain

but I don't want that

         

ergophobe

5:39 pm on Apr 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Similar but different from what Wizcraft has going on in
[webmasterworld.com...]

Basically, without the trailing slash, rewrites end up showing as the subdomain, rather than the domain that subdomain is mapped to.

This is just for a shared server that I sort of fool around on and I don't need to fix this, I just want to understand it.

I have a few domains on this server example.com, example1.org, example2.net with this file structure

/example
/example/example1
/example/example2

example.com is reached simply via h**p://example.com

The other domains can be reached via either

h**p://example1.example.com or h**p://example1.org

Now, let's say I want to rewrite everything, except what is going to the Inner Sanctum.


RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(is/.*¦is)$
RewriteRule !(.*)$ /outersanctum/$1 [L]

The problem is simple.

- if I type in h**p://example1.org/is/ there is no rewriting and it brings up h**p://example1.org/is/index.html just fine.

- BUT if I type in h**p://example1.org/is (no trailing slash) it goes to the right spot, but the address bad now says that I'm at h**p://example1.example.com/is/

Why does it now show as a subdomain in my address bar?

jdMorgan

7:43 pm on Apr 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteEngine on
RewriteCond %{REQUEST_URI}!^/(is/.*¦is)$
RewriteRule!(.*)$ /outersanctum/$1 [L]

That's pretty seriously messed-up.

First, the purpose of the exclusion conditions you often see in these rulesets is to prevent an 'infinite' rewrite loop. The path in the exclusionary RewriteCond should match the 'subdirectory' path.

Next, you cannot back-reference a negative pattern. The result will always be blank, which is why it's failing with the slash.

As to why it does an external redirect (shows the /subdirectory in the address bar), I can't tell. I suspect that it's triggering a different rule in your httpd.conf or .htaccess.

If I understand what you're trying to do, this code may work better.


RewriteEngine on
# Exclude special sudirectory "is" from rewrite,
RewriteCond %{REQUEST_URI} !^/is/?$
# Prevent infinite rewrite loop
RewriteCond %{REQUEST_URI} !^/outersanctum/
RewriteRule (.*) /outersanctum/$1 [L]

Jim

ergophobe

8:04 pm on Apr 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oy... stupid stupid stupid... In the first post I was trying to be coy with inner sanctum and outersanctum and made a bunch of careless typos and changed the whole thing. Stupid!

What I'm actually using works fine, doesn't reference a negative pattern and does want to stop an infinite loop as well as omit one directory from the rewrite.


RewriteCond %{REQUEST_URI}!^/index.php$
RewriteCond %{REQUEST_URI}!^/(is/.*¦is)$
RewriteRule!(.*)\.(gif¦jpg¦png¦css¦js¦doc¦pdf¦ico)$ /index.php [L]

That works fine and has all the behavior I want except that when the trailing slash is missing, it rewrites to the subdomain.

Sorry to waste time with that other garbage!

ergophobe

8:11 pm on Apr 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



BTW if I try to catch it and add the trailing slash I can get around it with an external redirect like


RewriteEngine On
RewriteCond %{REQUEST_URI} -d
RewriteCond %{REQUEST_URI}!^.*/$
RewriteRule (.*) [example.com$1...] [R]

RewriteCond %{REQUEST_URI}!^/index.php$
RewriteCond %{REQUEST_URI}!^/(is/.*¦is)$
RewriteRule!(.*)\.(gif¦jpg¦png¦css¦js¦doc¦pdf¦ico)$ /index.php [L]