Forum Moderators: phranque
RewriteOptions inherit
Options +Includes
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
AddHandler server-parsed .shtm
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
# Begin Cache Control
Header unset Pragma
FileETag None
Header unset ETag
# cache images/pdf/css docs for 1 Month
<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|svg|css)$">
Header set Cache-Control "max-age=2629000, public, must-revalidate"
Header unset Last-Modified
</FilesMatch>
# cache html/htm/xml/txt diles for 2 Days
<FilesMatch "\.(xml|txt|xsl|js|woff)$">
Header set Cache-Control "max-age=172800, must-revalidate"
</FilesMatch>
#End Cache Control
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/htm
AddOutputFilterByType DEFLATE text/shtm
AddOutputFilterByType DEFLATE text/php
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
#End Compression
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond {HTTP_HOST} !^(www\.example\.com)?$ [NC,OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Redirect permanent /folder/file.php https://www.domain.com/folder/page-name/ Redirect permanent /folder-name/file-name.shtm https://www.mydomain.com/folder-name/file-name.php RedirectMatch permanent ^/folder-name/another-folder/file-name.htm$ https://www.domain.com/folder-name/another-folder/file-name.shtm Redirect permanent /folder/file.php https://www.domain.com/folder/page-name/
Unfortunately, those redirects may be the source of some of the errors you're seeing. Redirect and Redirect Match use the Apache mod_alias module which does not play well with other mod_rewrite components you're using.
Since you need to use the WordPress block as it is supplied by WP, you should replace all those "redirect" lines with Rewrite Rules. You can't use redirect for http->https so it is best to replace them. Using rewrite patterns you may be able to save many lines of redirects.
We happen to have a similar situation going on here: [webmasterworld.com...] where you can find one easy way to replace all those lines using regex find/replace in a text editor.
Then it's time to fire up a text editor that does Regular Expressions, make a copy of your htaccess file, and apply these global changes (replace \1 with $1 depending on your RegEx engine):
^Redirect(?:Match)? 301 /(.+)
TO
RewriteRule \1 [R=301,L]
^Redirect(?:Match)? 410 /(.+)
TO
RewriteRule \1 - [G]
^Redirect(?:Match)? 403 /(.+)
TO
RewriteRule \1 - [F] ^Redirect(?:Match)? 301 /(.+) to find, and RewriteRule \1 [R=301,L] to replace and it should replace that old list of Redirect and RedirectMatch with a new list of RewriteRules.
^Redirect(?:Match)? 301 /(.+) /folder-name/sub-folder-name/file-name.php RewriteRule \1 [R=301,L] https://www.mydoman.com/folder/sub-folder/file-name/
Redirect permanent /(.+) to find, and RewriteRule /\1 [R=301,L] to replace, it converts this line: Redirect permanent /folder/file.php https://www.example.com/folder/page-name/to this line:
RewriteRule /folder/file.php https://www.example.com/folder/page-name/ [R=301,L]
it would be a royal pain in the butt to change all references in the file that show my domain name and individual page namesEr, do you not have a text editor? It doesn't even need to be a good one that does Regular Expressions; the barebones text editor that came preinstalled on your computer will do fine.
RewriteRule /folder/file.phpPatterns with leading slash are only used when lying loose in config (most likely in a VirtualHost envelope). In htaccess, omit the leading slash or the rule will not execute.
In htaccess, omit the leading slash or the rule will not execute.Oh, that's right lucy24. I added that error by trying to match the Redirect's format. Oops, my bad.
RewriteRule \1 [R=301,L] instead of RewriteRule /\1 [R=301,L] as suggested above for the "Replace" part of that search.