Forum Moderators: phranque
I have set the server up to have multiple blogs running from one install, each of which have their own directory under "content" for things like themes and plugins.
The cache wants a directory called "cache" in the "content" directory, but I'd like to redirect that th "content/EXAMPLE/cache".
The "EXAMPLE" part can be derived, as it will always be the domain name, minus the www. and the .com/.org etc.
Here's the exising code:
-----
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_¦wordpress¦wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]
-----
So, either I set it up to derive the "EXAMPLE" folder automatically, or if that isn't possible, would it be reasonable to add a specific set of rules for each domain?
Such as:
example.com/content/cache -> example.com/content/example/cache
example2.com/content/cache -> example2.com/content/example2/cache
I hope this is clear! Many thanks in advance,
Don
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.(com¦org¦net) [NC] will match the domain name, even when requested without www and put it in to
%2. You can't just drop this line into your ruleset and hope it will work. The
%2 can only be used by the line of code that immediately follows it. At present you are collecting a
%1 from the line immediately preceding the RewriteRule and so you will need to find a way to "transport" the value through two lines to reach the RewriteRule and have it still available. .
If there are a LOT of TLDs to match, and any of them are like .co.uk or .info (i.e. NOT three letters) then that part of the rule can be tweaked to accept one or two "words" of between two and perhaps seven or eight letters as "wildcard" values, instead of the fixed
(com¦org¦net) list. Additionally, are you sure you want a redirect? That will force the browser to make a new HTTP request for a new URL. Perhaps you need an internal rewrite - user sees the same URL, but content is fetched from a different folder inside the server. The location of that folder is not revealed to the user.
AddDefaultCharset UTF-8
RewriteEngine on
# RewriteBase / -- commented-out: "/" is the default, so this line is not needed
#
RewriteCond %{REQUEST_URI} /$
RewriteCond %{REQUEST_URI} !//
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} ![=]
RewriteCond %{HTTP:Cookie} !(comment_author_¦wordpress¦wp-postpass_)
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.(com¦org¦net)
RewriteCond %{DOCUMENT_ROOT}/content/cache/supercache/%2/$1/index.html.gz -f
RewriteRule (.*) /content/cache/supercache/%2/$1/index.html.gz [L]
Note that if you have different sites on "example.com" and "example.net" then the TLD *must* be included in the domain-subdirectory path and the rewrite, so the RewriteCond pattern would need to be changed to:
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+\.(com¦org¦net)) You don't need the <IfModule> container unless you require or desire this code to fail silently on servers where mod_rewrite support is not installed.
Jim