Force WWW
RewriteCond %{HTTP_HOST} ^mywebsite.dk
RewriteRule (.*) https://www.mywebsite.dk/$1 [R=301,L]
Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.dk/$1 [R,L]
did i do something wrong
RewriteCond %{HTTP_HOST} ^mywebsite.dk
RewriteRule (.*) https://www.mywebsite.dk/$1 [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.dk/$1 [R,L]
did i do something wrong
Not that I can see. But then you also haven’t shown the parts that you say aren’t working. Can you show your whole htaccess file and then describe what behavior you expect?
this is the whole .htaccess
# STARTNITRO
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
ExpiresActive On
#CSS JS XML TXT - 1 WEEK
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=604800, public"
ExpiresDefault "access plus 1 week"
</FilesMatch>
#JPG JPEG PNG GIF SWF SVG - 1 MONTH
<FilesMatch "\.(jpg|jpeg|png|gif|swf|svg|JPG|JPEG|PNG|GIF|SWF|SVG)$">
Header set Cache-Control "max-age=2592000, public"
Header set Last-Modified "Wed, 05 Jun 2009 06:40:46 GMT"
ExpiresDefault "access plus 1 month"
</FilesMatch>
#OTF ICO PDF FLV - 1 MONTH
<FilesMatch "\.(otf|ico|pdf|flv)$">
Header set Cache-Control "max-age=2592000, public"
ExpiresDefault "access plus 1 month"
</FilesMatch>
# ENDNITRO
# BEGIN OpenCart
# 1. To use URL Alias you need to be running apache with mod_rewrite enabled.
# 2. In your OpenCart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com
# Rabbit Rabbit Security Upgrade
Options +SymLinksIfOwnerMatch
# Prevent Directory listing
Options -Indexes
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
RewriteBase /
# If using subdirectory, update RewriteBase /
# Store URL: yourstore.com/shop
# Update to: RewriteBase /shop/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
### Force WWW ###
RewriteCond %{HTTP_HOST} ^mywebsite\.dk
RewriteRule (.*) https://www.mywebsite.dk/$1 [R=301,L]
## Force SSL ###
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.dk/$1 [R,L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.
# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off
# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off
# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M
# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M
# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200
# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200
# 7. disable open_basedir limitations
# php_admin_value open_basedir none
# END OpenCart
# BEGIN Rabbit Rabbit
# Enable Gzip Compression
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
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
# Remove Browser Bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
FileETag MTime Size
# END Rabbit Rabbit
And in that whole htaccess file, what behavior are you expecting that isn’t working?
at the end of the .htaccess i put this:
RewriteCond %{HTTP_HOST} ^mywebsite\.dk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.dk$
RewriteRule ^utilfreds$ "https\:\/\/www\.mywebsite\.dk\/contact" [R=301,L]
I suspect the problem is because you’ve already rewritten every request to index.php.
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
After that, you’ll never match “utilfreds” because it would have already been rewritten to index.php?_route_=utilfreds
.
In fact, your force www and ssl code probably won’t do what you expect either. http://mywebsite.dk/utilfreds
will end up redirecting to https://www.mywebsite.dk/index.php?_route_=utilfreds
.
Order matters. You need to think carefully about which rewrite rules need to run before others. Your force www and ssl rules should probably run first. Then rewrites for any specific paths, such as utilfreds. Then, finally, your generic catch-all rewrite to index.php.
it is working now when i put
at the bottom of the htaccess code, problem is, i like to have all my rewrites in the bottom, but many thanks anyways
freshy,
Simply put your code before the “generic” redirect-everything-to-index.php:
# Force WWW
RewriteCond %{HTTP_HOST} ^mywebsite\.dk [NC]
RewriteRule (.*) https://www.mywebsite.dk/$1 [R=301,L]
# Force SSL
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://www.mywebsite.dk/$1 [R=301,L]
# ... then, do NOT forget to check whether the request exists as a file or directory before sending to index.php!
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? index.php?_route_=%{REQUEST_URI} [L]
Three things:
...
RewriteRule .? http://www.mywebsite.dk%{REQUEST_URI} {{optional flags}]
...
Here, the .? ensures a match and the {REQUEST_URI} variable is already available (and handles the / between the domain and URI).
More comments:
Regards,
DK
i did what you said except
#2. QSA, it is really needed in my situation because i got alot of queries in my site that is associated with request uri.
Thanks alot by the way, if you have any more suggestion to my .htaccess that could make my site faster or optimize, please say so.
Thanks again!
freshy,
No worry about the QSA, then, as index.php should handle the _route_ variable before getting on to any other “garbage” in the QUERY_STRING. My only concern was that it’s not needed UNLESS it’s there for a purpose and it would be unusual for there to be one; since you say that there is a valid reason, all the more need to use QSA.
As for any other optimization, I’m not sure of the value of the core code (all the cache expiration information) so I don’t want to comment on that. However, the general rule is to move all unnecessary code OUT of the .htaccess files because they’re generally read and parsed/executed MANY times for each file request (including not just your script but images, CSS, JS, etc.). If you can (VPS/dedicated server), move as much of your code to httpd.conf or httpd-vhosts.conf. A modified KISS principle applies (Keep It Short, Stupid) to .htaccess files to keep your site rolling along.
Regards,
DK
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.