need help with .htaccess

  • stevennestler
  • Newbie
  • Newbie
  • stevennestler
  • Posts: 6
  • Loc: Coral Springs, FL

Post 3+ Months Ago

I am having difficulty adding a command to my .htaccess file. I don't understand the syntax, and I need some help. So far, every attempt has caused the site's design to crash.

The current file is:
Code: [ Select ]
##
# @package Joomla
# @copyright Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved.
# @license GNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
##

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

<ifModule mod_headers.c>
Header unset ETag
</ifModule>
FileETag None

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
##Redirect non-www to www (both: http + https)

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 2 years"
ExpiresByType image/gif "access plus 2 years"
ExpiresByType image/jpeg "access plus 2 years"
ExpiresByType image/png "access plus 2 years"
ExpiresByType image/x-icon "access plus 2 years"
ExpiresByType text/css "access plus 2 years"
ExpiresByType text/javascript "access plus 2 years"
ExpiresByType application/x-javascript "access plus 2 years"
ExpiresByType application/x-shockwave-flash "access plus 2 years"
</IfModule>
  1. ##
  2. # @package Joomla
  3. # @copyright Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved.
  4. # @license GNU General Public License version 2 or later; see LICENSE.txt
  5. ##
  6. ##
  7. # READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
  8. #
  9. # The line just below this section: 'Options +FollowSymLinks' may cause problems
  10. # with some server configurations. It is required for use of mod_rewrite, but may already
  11. # be set by your server administrator in a way that dissallows changing it in
  12. # your .htaccess file. If using it causes your server to error out, comment it out (add # to
  13. # beginning of line), reload your site in your browser and test your sef url's. If they work,
  14. # it has been set by your server administrator and you do not need it set here.
  15. ##
  16. ## Can be commented out if causes errors, see notes above.
  17. Options +FollowSymLinks
  18. <ifModule mod_headers.c>
  19. Header unset ETag
  20. </ifModule>
  21. FileETag None
  22. ## Mod_rewrite in use.
  23. RewriteEngine On
  24. ## Begin - Rewrite rules to block out some common exploits.
  25. # If you experience problems on your site block out the operations listed below
  26. # This attempts to block the most common type of exploit `attempts` to Joomla!
  27. #
  28. # Block out any script trying to base64_encode data within the URL.
  29. RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
  30. # Block out any script that includes a <script> tag in URL.
  31. RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
  32. # Block out any script trying to set a PHP GLOBALS variable via URL.
  33. RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
  34. # Block out any script trying to modify a _REQUEST variable via URL.
  35. RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
  36. # Return 403 Forbidden header and show the content of the root homepage
  37. RewriteRule .* index.php [F]
  38. #
  39. ## End - Rewrite rules to block out some common exploits.
  40. ## Begin - Custom redirects
  41. #
  42. # If you need to redirect some pages, or set a canonical non-www to
  43. # www redirect (or vice versa), place that code here. Ensure those
  44. # redirects use the correct RewriteRule syntax and the [R=301,L] flags.
  45. #
  46. ## End - Custom redirects
  47. ##
  48. # Uncomment following line if your webserver's URL
  49. # is not directly related to physical file paths.
  50. # Update Your Joomla! Directory (just / for root).
  51. ##
  52. # RewriteBase /
  53. ## Begin - Joomla! core SEF Section.
  54. #
  55. RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  56. #
  57. # If the requested path and file is not /index.php and the request
  58. # has not already been internally rewritten to the index.php script
  59. RewriteCond %{REQUEST_URI} !^/index\.php
  60. # and the request is for something within the component folder,
  61. # or for the site root, or for an extensionless URL, or the
  62. # requested URL ends with one of the listed extensions
  63. RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
  64. # and the requested path and file doesn't directly match a physical file
  65. RewriteCond %{REQUEST_FILENAME} !-f
  66. # and the requested path and file doesn't directly match a physical folder
  67. RewriteCond %{REQUEST_FILENAME} !-d
  68. # internally rewrite the request to the index.php script
  69. RewriteRule .* index.php [L]
  70. #
  71. ## End - Joomla! core SEF Section.
  72. ##Redirect non-www to www (both: http + https)
  73. RewriteEngine On
  74. RewriteCond %{HTTPS} off
  75. RewriteCond %{HTTP_HOST} !^www.(.*)$ [NC]
  76. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
  77. RewriteCond %{HTTPS} on
  78. RewriteCond %{HTTP_HOST} !^www.(.*)$ [NC]
  79. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
  80. <IfModule mod_expires.c>
  81. ExpiresActive On
  82. ExpiresByType text/html "access plus 2 years"
  83. ExpiresByType image/gif "access plus 2 years"
  84. ExpiresByType image/jpeg "access plus 2 years"
  85. ExpiresByType image/png "access plus 2 years"
  86. ExpiresByType image/x-icon "access plus 2 years"
  87. ExpiresByType text/css "access plus 2 years"
  88. ExpiresByType text/javascript "access plus 2 years"
  89. ExpiresByType application/x-javascript "access plus 2 years"
  90. ExpiresByType application/x-shockwave-flash "access plus 2 years"
  91. </IfModule>


I am hoping to add:

Code: [ Select ]
<IfModule mod_rewrite.c>

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Cookie} devicePixelRatio [NC]
RewriteRule \.(?:jpe?g|gif|png|bmp)$ /retinaimages.php [NC,L]
  1. <IfModule mod_rewrite.c>
  2. Options +FollowSymlinks
  3. RewriteEngine On
  4. RewriteBase /
  5. RewriteCond %{HTTP:Cookie} devicePixelRatio [NC]
  6. RewriteRule \.(?:jpe?g|gif|png|bmp)$ /retinaimages.php [NC,L]


Any help would be appreciated.
Steven
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

When you say crash, is it saying "Internal Server Error"? If so can you try and find the error_logs for your website. It should state in there exactly what the problem is and that would help figure out what is the problem in your .htaccess file.

Also it looks like the last part you tried to add is:

Code: [ Select ]
<IfModule mod_rewrite.c>

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Cookie} devicePixelRatio [NC]
RewriteRule \.(?:jpe?g|gif|png|bmp)$ /retinaimages.php [NC,L]
  1. <IfModule mod_rewrite.c>
  2. Options +FollowSymlinks
  3. RewriteEngine On
  4. RewriteBase /
  5. RewriteCond %{HTTP:Cookie} devicePixelRatio [NC]
  6. RewriteRule \.(?:jpe?g|gif|png|bmp)$ /retinaimages.php [NC,L]


Don't forget to close the IfModule area with:

Code: [ Select ]
</ifModule>


After the last rewrite rule there.
  • stevennestler
  • Newbie
  • Newbie
  • stevennestler
  • Posts: 6
  • Loc: Coral Springs, FL

Post 3+ Months Ago

Thanks for the reply.
Unfortunately, I'm not only unable to deal with the code, but my limited vocabulary doesn't even accurately describe the problem!
The entire site doesn't crash; it is the design elements that are all out of place; I wasn't sure how to describe it.
I tried the </ifModule> close after my addition; I tried it with closing the previous paragraph, as well as without.

So far, I can't quite get it right.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 71 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.