Static url, htaccess, please help

here’s where I am now -

I am attempting to serve Static Content from a Cookieless Domain. My host is hostgator.

my domain is www.urleditedbymoderator.com and my subdomain is static.urleditedbymoderator.com

I contacted hostgator to set the CNAME according to these instructions

When you create the CNAME record you want to enter your static domain/subdomain as the “label”, “name”, or “alias” and your A record domain as the “content” or “value”.  

I then went to my site and changed the name of an image file from

http://www.urleditedbymoderator.com/wp-content/uploads/2010/01/lion500.png

to

http://static.walidmrealtor.co /wp-content/uploads/2010/01/lion500.png

I get the following error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@static.urleditedbymoderator.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at static.urleditedbymoderator.co Port 80

When I contact hostgator, the technician informs me there is nothing they can do, and that this is an ht.access error.

Here is my ht.access, does anyone know what should be modified to make this work? I am not a guru when it comes to apache…

BEGIN WPSuperCache

<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_USER_AGENT} !^.(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]

RewriteCond %{REQUEST_URI} !^.[^/]$
RewriteCond %{REQUEST_URI} !^.
//.$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.
=.*
RewriteCond %{HTTP:Cookie} !^.(comment_author_|wordpress|wp-postpass_).$
RewriteCond %{HTTP_USER_AGENT} !^.(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
</IfModule>

END WPSuperCache

BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

END WordPress

disable directory browsing

Options All -Indexes

1 YEAR

Header set Cache-Control “public”
Header set Expires “Thu, 15 Apr 2010 20:00:00 GMT”
Header unset Last-Modified

2 HOURS

Header set Cache-Control “max-age=7200, must-revalidate”

CACHED FOREVER

MOD_REWRITE TO RENAME EVERY CHANGE

Header set Cache-Control “public”
Header set Expires “Thu, 15 Apr 2010 20:00:00 GMT”
Header unset Last-Modified

BEGIN Compress text files

SetOutputFilter DEFLATE

END Compress text files

BEGIN Expire headers

ExpiresActive On
ExpiresDefault “access plus 1 seconds”
ExpiresByType image/x-icon “access plus 2592000 seconds”
ExpiresByType image/jpeg “access plus 2592000 seconds”
ExpiresByType image/png “access plus 2592000 seconds”
ExpiresByType image/gif “access plus 2592000 seconds”
ExpiresByType application/x-shockwave-flash “access plus 2592000 seconds”
ExpiresByType text/css “access plus 604800 seconds”
ExpiresByType text/javascript “access plus 216000 seconds”
ExpiresByType application/x-javascript “access plus 216000 seconds”
ExpiresByType text/html “access plus 600 seconds”
ExpiresByType application/xhtml+xml “access plus 600 seconds”

END Expire headers

BEGIN Cache-Control Headers

Header set Cache-Control "max-age=2592000, public"

Header set Cache-Control "max-age=604800, public"

Header set Cache-Control "max-age=216000, private"

Header set Cache-Control "max-age=600, private, must-revalidate"

END Cache-Control Headers

BEGIN Turn ETags Off

Header unset ETag

FileETag None

END Turn ETags Off

BEGIN Remove Last-Modified Header

Header unset Last-Modified

END Remove Last-Modified Header

RewriteCond %{HTTP_HOST} ^urleditedbymoderator.com$
RewriteRule ^/?$ “http\:\/\/www\.urleditedbymoderator\.com\/” [R=301,L]

Thank you molona :slight_smile:

I appreciate that!

Do you know what I can do to get rid of the error? The site I referenced seems pretty straight forward, and I think I’ve done what I should thus far. http://wwwDOTravelrumbaDOTcom/blog/static-cookieless-domain/

Thanks molona!

Walidm,

In starting to read through your post, I saw an error in your third code block: A space after the domain name and before the / to continue the URL. To Linux, that space is critical as it delimits the section of mod_rewrite code in the parser and sends to the type of command, the regex to match (against the {REQUEST_URI} string), the redirection (which was merely your protocol and domain) then FLAGS, not a continuation of the redirection. I didn’t see that in a quick look at the (TOO) lengthy .htaccess (you DO realize that all that must be read for EVERY file request, not just for php scripts, don’t you?). Anyway, improper syntax within mod_rewrite statements is a sure way to guarantee 500 errors!

Same with the ErrorDocument as it’s an ErrorDocument {type} {absolute redirection} and NOTHING more!

SitePoint’s thread response generator stopped that but I fear that my continuing with a more detailed review of your full .htaccess file would be merely an exercise in frustration.

Regards,

DK

Thanks Dk, that space is in there because the “m” was removed from the dot com in order to post here. Sitepoint will not let new users post addresses or links and the forum moderator deleted all the posts that would have allowed me to post reference material and information.

walidm,

The [code] block would have allowed that.

# BEGIN WPSuperCache
[COLOR="Red"]# <IfModule mod_rewrite.c>
# No webmaster worth his salt would leave that in their code!
# It wastes CPU cycles on EVERY request![/COLOR]
RewriteEngine On
RewriteBase /
[COLOR="Gray"]AddDefaultCharset UTF-8
# move this out of the mod_rewrite code as it's an Apache directive[/COLOR]
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*[COLOR="Red"]//[/COLOR].*$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\\ Wii|Nitro|Nokia|Opera\\ Mini|Palm|PlayStation\\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\\ Obigo|LGE\\ VX|webOS|Nokia5800).*
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
# That looks into the physical path to files which, IMHO, is not correct -
# certainly, %{HTTP_HOST} (e.g., www.example.com) is not in the physical path!
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]

RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*[COLOR="Red"]//[/COLOR].*$
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\\ Wii|Nitro|Nokia|Opera\\ Mini|Palm|PlayStation\\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\\ Obigo|LGE\\ VX|webOS|Nokia5800).*
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
[COLOR="Red"]</IfModule>[/COLOR]

# END WPSuperCache

# BEGIN WordPress
[COLOR="Red"]<IfModule mod_rewrite.c>
# ARGH!  AGAIN?[/COLOR]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
[COLOR="Red"]</IfModule>[/COLOR]

# END WordPress

# disable directory browsing
[COLOR="Gray"]Options All -Indexes
# move to top, also, as a core directive[/COLOR]
# 1 YEAR

Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified

# 2 HOURS

Header set Cache-Control "max-age=7200, must-revalidate"

# CACHED FOREVER
# MOD_REWRITE TO RENAME EVERY CHANGE

Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified

# BEGIN Compress text files

SetOutputFilter DEFLATE

# END Compress text files

# BEGIN Expire headers

ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"

# END Expire headers

# BEGIN Cache-Control Headers

Header set Cache-Control "max-age=2592000, public"

Header set Cache-Control "max-age=604800, public"

Header set Cache-Control "max-age=216000, private"

Header set Cache-Control "max-age=600, private, must-revalidate"

# END Cache-Control Headers

# BEGIN Turn ETags Off

Header unset ETag

FileETag None
# END Turn ETags Off

# BEGIN Remove Last-Modified Header

Header unset Last-Modified

# END Remove Last-Modified Header

RewriteCond %{HTTP_HOST} ^urleditedbymoderator.com$
RewriteRule ^/?$ [COLOR="Red"]"[/COLOR]http[COLOR="Red"]\\[/COLOR]:[COLOR="Red"]\\[/COLOR]/[COLOR="Red"]\\[/COLOR]/www[COLOR="Red"]\\[/COLOR].urleditedbymoderator[COLOR="Red"]\\[/COLOR].com[COLOR="Red"]\\[/COLOR]/" [R=301,L]
[COLOR="Red"]# NEVER escape redirections (except encoding of reserved characters which is done with %xxx
[/COLOR]

General comments:

  1. Move all the Apache directive outside the mod_rewrite code (it keeps things clean ESPECIALLY when the mod_rewrite is confusing you).

  2. KNOW whether mod_rewrite is enabled! Do NOT test this on EVERY FILE REQUEST - TWICE!

  3. WP code is exceptionally “greedy” meaning that it is supposed to capture EVERYTHING that reaches it’s mod_rewrite code. Saying that, I’m not sure what bells and whistles the WPSuperCache code is supposed to be using (I don’t believe that the physical path information is correct, though) but it should prevent anything of reason reaching the “normal” WP code which, upon being parsed for your request, will RErewrite the WPSuperCache redirection straight to index.php (given that the WPSuperCache redirection is not to a file or directory).

If it were me, I’d not bother with the WPSuperCache and rely merely on WP’s “normal” code.

As for the gzip bit at the end, it, too, is looking to be greedy.

In the end, pick one of three and discard (at least comment out with RewriteEngine off … Rewrite Engine on around your code sections - Comment out the gzip directives individually) the rest.

  1. Redirections do NOT get their characters escaped with \'s! Not only does that not do anything, it looks horribly silly! Reserved characters in your URI are a different matter as they require ENCODING (which is NOT the same as escaping their characters).

Regards,

DK

walidm,

Thanks for the PM correcting my path through this thread. To restate for others, walidm merely wants to have static files served from a subdomain. Of course, that subdomain’s position in his domain’s physical heirarchy could be problematic if you don’t call your static images via an absolute link to the subdomain.

The only part of your first post which might inhibit your static file URIs which I found would be

RewriteCond &#37;{HTTP_HOST} ^urleditedbymoderator.com$
RewriteRule ^/?$ [COLOR="Red"]"[/COLOR]http[COLOR="Red"]\\[/COLOR]:[COLOR="Red"]\\[/COLOR]/[COLOR="Red"]\\[/COLOR]/www[COLOR="Red"]\\[/COLOR].urleditedbymoderator[COLOR="Red"]\\[/COLOR].com[COLOR="Red"]\\[/COLOR]/[COLOR="Red"]"[/COLOR] [R=301,L] 

I gave you some “heat” over the incorrect use of the \ in the redirection which may be due to a copy and paste (that’ll teach you - and others, I hope!). However, the redirection of the non-subdomain to the www’d version should NOT effect subdomain requests (which [a] should bypass this .htaccess and [b] would not match the domain name).

Apologies for my lack of understanding of the original question.

Regards,

DK

I use hostgator for hosting. After investigation, hostgator has an option via the cpanel, to redirect your url. I believe once you fill in the “blanks” in the redirect form, the code is inserted into the .htaccess.

Should all of the highlighted slashes be removed, will the code be formatted properly?

walidm,

Remove the quotes, too!

Regards,

DK

Put this code in .htaccess and all is ok ! This is for Joomla, Wordpress and all site !

Header set Cache-Control “public”
ExpiresActive On
ExpiresDefault A18000
ExpiresByType image/gif A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
Expiresbytype text/js A21600
Expiresbytype text/js “access plus 1 year”
ExpiresByType text/php “access plus 1 year”
ExpiresByType text/html “access plus 1 year”
ExpiresByType text/css “access plus 1 year”
ExpiresByType image/gif “access plus 1 year”
Header set Cache-Control “public”
ExpiresByType image/jpg “access plus 1 year”
Header set Cache-Control “public”
ExpiresByType image/jpeg “access plus 1 year”
Header set Cache-Control “public”
ExpiresByType image/png “access plus 1 year”
Header set Cache-Control “public”

<FilesMatch “\\.(js|css|html|htm|php|xml)$”>
SetOutputFilter DEFLATE
</FilesMatch>

[EDIT: Link Removed]