Forum Moderators: phranque
RewriteCond %{REQUEST_URI} !\.(gif|jpg|js|mp3|png)$
RewriteRule ^[^/]*/(images|search|scripts|sounds)(.+) $1$2 [QSA]
http:// localhost/version3/www.example1.com/
http:// localhost/version3/www.example2.com/
http:// localhost/version3/www.example3.com/
http:// localhost/version3/www/example1.com/
http:// localhost/version3/www/example2.com/
http:// localhost/version3/www/example3.com/
... (images|search|scripts|sounds)(.+) $1$2 [QSA] ((?:images|search|scripts|sounds)/.+) if ($_SERVER['HTTP_HOST']!='localhost' && substr($_SERVER['HTTP_HOST'],0,7)!='192.168')
{//live
$p0 = explode('www.',$_SERVER['HTTP_HOST'],2);
}
else
{//local
$p0 = explode('www.',$_SERVER['REQUEST_URI'],2);
$p1 = explode('/',$p0[1],2);
}
http:// www.example1.com/
http://localhost/Version 3/www.example1.com/
http:// www.example1.com/www.example1.com/images/
http:// www.example1.com/images/
http://localhost/Version 3/www.example1.com/www.example1.com/images/
http://localhost/Version 3/www.example1.com/images/
RewriteCond %{REQUEST_URI} !\.(gif|jpg|js|mp3|png)$
RewriteRule ^[^/]*/(images|search|scripts|sounds)(.+) $1$2 [QSA]
http:// localhost/Version 3/www.example.com/
http:// localhost/Version 3/www.example.com/www.example.com/crazy-penguins-on-my-front-lawn.png
http:// localhost/Version 3/www.example.com/crazy-penguins-on-my-front-lawn.png
#1 Wouldn't it be more efficient if the body of the rule specified the extensions the rule does want, instead of going to a condition to exclude the ones it doesn't want?
#2 Why does the pattern start with ^[^/]*/ ?
#3 A literal period in mid-URL isn't absolutely forbidden-- apache dot org themselves have buckets of them-- but it's really better if you can get rid of them.
#4
... (images|search|scripts|sounds)(.+) $1$2 [QSA]
Can I assume the first group is always followed by a directory slash and then more stuff? If so it could also be expressed as ...
#5 The [QSA] isn't needed, because that's the default behavior unless you've explicitly added a new query. It also, of course, isn't needed if there was no query in the first place. Your rule doesn't give any hint about what the file extension is, only what it isn't, so I can't guess. What the rule does need-- and I'm surprised there haven't been unintended consequences-- is an [L] flag.
Oh and Psst! Although it has to be "example" in posts, it doesn't have to be dot com. You can say .org, .net, .uk, .xyz as much as you like if you need to distinguish among different domain names.
Obviously I can't use $_SERVER['HTTP_HOST'] for localhost/192.168.*.* so I make sure there is a www.
if ($_COOKIE["silence"] || $newval != "index.html" || strpos($_SERVER['HTTP_HOST'],":")) #1 Wouldn't it be more efficient if the body of the rule specified the extensions the rule does want, instead of going to a condition to exclude the ones it doesn't want?
I think this post should clarify things to that question now.
(^|/|\.html)$ (([^/]+/)*[^/.]+) ...when I access a domain the following way...http:// localhost/Version 3/www.example.com/
...the file crazy-penguins-on-my-front-lawn.png is located (to Apache) at...http:// localhost/Version 3/www.example.com/www.example.com/crazy-penguins-on-my-front-lawn.png
...and appears to load in the browser from...http:// localhost/Version 3/www.example.com/crazy-penguins-on-my-front-lawn.png
So highlighted in blue below is where on localhost the domain is emulated...RewriteCond %{REQUEST_URI} !\.(gif|jpg|js|mp3|png)$
RewriteRule ^[^/]*/(images|search|scripts|sounds)(.+) $1$2 [QSA]
...and appears to load in the browser from...
http:// localhost/Version 3/www.example.com/www.example.com/crazy-penguins-on-my-front-lawn.png
www\.example\.com www\.([a-z-]+\.com) (www\.[a-z-]+\.com) RewriteCond %{REQUEST_URI} !\.(gif|jpg|js|mp3|png)$
RewriteRule ^[^/]*/(images|search|scripts|sounds)(.+) $1$2 [QSA]
^[^/]*
http:// localhost/Version 3/www.example.com/www.example.com/
(images|search|scripts|sounds)
shared public root
Version 3/
specific domain, emulates live though access via localhost
Version 3/www.example.com/
assets for this domain stored in this folder
Version 3/www.example1.com/www.example1.com/
image assets
Version 3/www.example1.com/www.example1.com/images/
script assets
Version 3/www.exampl1e.com/www.example1.com/scripts/
assets for this domain stored in this folder
Version 3/www.example2.com/www.example2.com/
image assets
Version 3/www.example2.com/www.example2.com/images/
script assets
Version 3/www.example2.com/www.example2.com/scripts/
I don't get the connection between the two blue parts.
RewriteCond %{REQUEST_URI} !\.(gif|jpg|js|mp3|png)$
RewriteRule ^[^/]*/(admin|blog|contact|forums)(.+) $1$2 [QSA]
http:// www.example1.com/blog/
http:// www.example2.com/blog/
http:// www.example3.com/blog/
http:// localhost/version3/.local.htaccess
http:// localhost/version3/blog/
/public_html/.htaccess
/public_html/blog/
http:// localhost/version3/www.example2.com/images/crazy-penguins-on-my-front-lawn.png
http:// localhost/version3/www.example2.com/www.example2.com/images/crazy-penguins-on-my-front-lawn.png
http:// localhost/version3/www.example2.com/www/example2.com/images/crazy-penguins-on-my-front-lawn.png
www\.([a-z-]+\.com)
>>
www/$1 and so on until the cows come home, without making it impossible for you to find stuff in the root.
Have I NOW got it right?
The form "browser URL" is confusing because supporting files don't have browser URLs-- that is, the user doesn't normally see where they're coming from.
so by keeping it as a rewrite instead of a redirect, you save the browser from having to make a fresh request every single time.
So the first piece of the request-- the piece that contains the directory name-- is thrown away in the case of shared files. But how did it get into the request in the first place? If it didn't come from htaccess, it must have come from php. And why is php adding something that isn't going to be used?
See, I've got this lurking suspicion that this isn't an apache issue at all. It may be better solved at the php level.
Unless you're particularly concerned about human users snooping into the html and finding the "real" paths laid bare before their eyes.
RewriteRule ^(scripts\/|themes\/) - [L]
RewriteCond %{REQUEST_URI} !.*/(admin|blog|contact|forums)
RewriteRule !\.(css|js|xml|zip)$ rewrite.php
because you would have worked that out for yourself without all those sleepless nights
RewriteRule ^(scripts\/|themes\/) - [L]
RewriteRule ^(scripts|themes)/ - [L] RewriteCond %{REQUEST_URI} !.*/(admin|blog|contact|forums)
RewriteCond %{REQUEST_URI} !.*/(admin|blog|contact|forums)
RewriteRule !\.(css|js|xml|zip)$ rewrite.php
because you would have worked that out for yourself without all those sleepless nights
Are you working with sites that already exist, so all the files have got established URLs?
If not, it seems as if you could save yourself a lot of bother by sorting things at the directory level.
why would I want to make more work for myself