Forum Moderators: phranque
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?
RewriteEngine on
RewriteCond %{REQUEST_URI}!^/(is/.*¦is)$
RewriteRule!(.*)$ /outersanctum/$1 [L]
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]
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]
Sorry to waste time with that other garbage!
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]