Reputation: 369
I've had a look at a few threads, which are broadly based on this. The problem I have is that I am redirecting all non www URL's to www and then push http to https, so my eventual URL starts as https://www.
From there, the redirects on internal pages start to append the variables at the end of the URL, IE:
http://www.domain.co.uk/internal-doors/range
- when redirected to https://www.domain.co.uk/internal-doors/range
formats as https://www.domain.co.uk/internal-doors/range?id=range
- appending all my URL variables at the end.
My full htaccess is as follows:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteBase /
Options -Indexes
RewriteRule ^(admin|blog|images|imports)($|/) - [L]
ErrorDocument 404 /404.php
RewriteRule ^internal-doors/([^/\.]+)/([^/\.]+)/?$ offering.php?id=$1&o=$2 [NC,QSA]
RewriteRule ^internal-doors/([^/\.]+)/?$ detail.php?id=$1 [NC,QSA]
RewriteRule ^information/([^/\.]+)/?$ content.php?p=$1 [L]
RewriteRule ^external-doors/([^/\.]+)/([^/\.]+)/?$ offering.php?id=$1&o=$2 [NC,QSA]
RewriteRule ^external-doors/([^/\.]+)/?$ detail.php?id=$1 [NC,QSA]
RewriteRule ^accessories/([^/\.]+)/?$ detail.php?id=$1 [NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ range.php?s=$1&r=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ category.php?s=$1 [L,QSA]
<IfModule mod_expires.c>
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 2592000 seconds"
ExpiresByType application/x-javascript "access plus 2592000 seconds"
ExpiresByType application/javascript "access plus 2592000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2692000, public"
</FilesMatch>
<FilesMatch "\\.(css)$">
Header set Cache-Control "max-age=2692000, public"
</FilesMatch>
<FilesMatch "\\.(js)$">
Header set Cache-Control "max-age=2592000, private"
</FilesMatch>
<FilesMatch "\\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</FilesMatch>
Header unset ETag
Header unset Last-Modified
</IfModule>
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Hopefully this makes sense. There are a few other threads about this, but I can't see a clear definitive answer to stop URL's appending at the end of a redirect.
Thanks in advance.
Upvotes: 0
Views: 550
Reputation: 33813
To clarify the summary I gave, the order in which the rules are process is important. firstly enforce the https protocol and then deal with any other rewrite rules that handle dynamic url rewriting.
# Enforce https
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
# other rules
Upvotes: 1